vendor/golang.org/x/net/html/parse.go
changeset 256 6d9efbef00a9
parent 251 1c52a0eeb952
child 265 05c40b36d3b2
equal deleted inserted replaced
255:4f153a23adab 256:6d9efbef00a9
   661 			return true
   661 			return true
   662 		case a.Head:
   662 		case a.Head:
   663 			// Ignore the token.
   663 			// Ignore the token.
   664 			return true
   664 			return true
   665 		case a.Template:
   665 		case a.Template:
       
   666 			// TODO: remove this divergence from the HTML5 spec.
       
   667 			//
       
   668 			// We don't handle all of the corner cases when mixing foreign
       
   669 			// content (i.e. <math> or <svg>) with <template>. Without this
       
   670 			// early return, we can get into an infinite loop, possibly because
       
   671 			// of the "TODO... further divergence" a little below.
       
   672 			//
       
   673 			// As a workaround, if we are mixing foreign content and templates,
       
   674 			// just ignore the rest of the HTML. Foreign content is rare and a
       
   675 			// relatively old HTML feature. Templates are also rare and a
       
   676 			// relatively new HTML feature. Their combination is very rare.
       
   677 			for _, e := range p.oe {
       
   678 				if e.Namespace != "" {
       
   679 					p.im = ignoreTheRemainingTokens
       
   680 					return true
       
   681 				}
       
   682 			}
       
   683 
   666 			p.addElement()
   684 			p.addElement()
   667 			p.afe = append(p.afe, &scopeMarker)
   685 			p.afe = append(p.afe, &scopeMarker)
   668 			p.framesetOK = false
   686 			p.framesetOK = false
   669 			p.im = inTemplateIM
   687 			p.im = inTemplateIM
   670 			p.templateStack = append(p.templateStack, inTemplateIM)
   688 			p.templateStack = append(p.templateStack, inTemplateIM)
   681 			return false
   699 			return false
   682 		case a.Template:
   700 		case a.Template:
   683 			if !p.oe.contains(a.Template) {
   701 			if !p.oe.contains(a.Template) {
   684 				return true
   702 				return true
   685 			}
   703 			}
   686 			// TODO: remove this divergence from the HTML5 spec.
   704 			// TODO: remove this further divergence from the HTML5 spec.
   687 			//
   705 			//
   688 			// See https://bugs.chromium.org/p/chromium/issues/detail?id=829668
   706 			// See https://bugs.chromium.org/p/chromium/issues/detail?id=829668
   689 			p.generateImpliedEndTags()
   707 			p.generateImpliedEndTags()
   690 			for i := len(p.oe) - 1; i >= 0; i-- {
   708 			for i := len(p.oe) - 1; i >= 0; i-- {
   691 				if n := p.oe[i]; n.Namespace == "" && n.DataAtom == a.Template {
   709 				if n := p.oe[i]; n.Namespace == "" && n.DataAtom == a.Template {
   726 		switch p.tok.DataAtom {
   744 		switch p.tok.DataAtom {
   727 		case a.Html:
   745 		case a.Html:
   728 			return inBodyIM(p)
   746 			return inBodyIM(p)
   729 		case a.Basefont, a.Bgsound, a.Link, a.Meta, a.Noframes, a.Style:
   747 		case a.Basefont, a.Bgsound, a.Link, a.Meta, a.Noframes, a.Style:
   730 			return inHeadIM(p)
   748 			return inHeadIM(p)
   731 		case a.Head, a.Noscript:
   749 		case a.Head:
       
   750 			// Ignore the token.
       
   751 			return true
       
   752 		case a.Noscript:
       
   753 			// Don't let the tokenizer go into raw text mode even when a <noscript>
       
   754 			// tag is in "in head noscript" insertion mode.
       
   755 			p.tokenizer.NextIsNotRawText()
   732 			// Ignore the token.
   756 			// Ignore the token.
   733 			return true
   757 			return true
   734 		}
   758 		}
   735 	case EndTagToken:
   759 	case EndTagToken:
   736 		switch p.tok.DataAtom {
   760 		switch p.tok.DataAtom {
  1788 			p.tokenizer.NextIsNotRawText()
  1812 			p.tokenizer.NextIsNotRawText()
  1789 			// Ignore the token.
  1813 			// Ignore the token.
  1790 			return true
  1814 			return true
  1791 		case a.Script, a.Template:
  1815 		case a.Script, a.Template:
  1792 			return inHeadIM(p)
  1816 			return inHeadIM(p)
       
  1817 		case a.Iframe, a.Noembed, a.Noframes, a.Noscript, a.Plaintext, a.Style, a.Title, a.Xmp:
       
  1818 			// Don't let the tokenizer go into raw text mode when there are raw tags
       
  1819 			// to be ignored. These tags should be ignored from the tokenizer
       
  1820 			// properly.
       
  1821 			p.tokenizer.NextIsNotRawText()
       
  1822 			// Ignore the token.
       
  1823 			return true
  1793 		}
  1824 		}
  1794 	case EndTagToken:
  1825 	case EndTagToken:
  1795 		switch p.tok.DataAtom {
  1826 		switch p.tok.DataAtom {
  1796 		case a.Option:
  1827 		case a.Option:
  1797 			if p.top().DataAtom == a.Option {
  1828 			if p.top().DataAtom == a.Option {
  2112 		// Ignore the token.
  2143 		// Ignore the token.
  2113 	}
  2144 	}
  2114 	return true
  2145 	return true
  2115 }
  2146 }
  2116 
  2147 
       
  2148 func ignoreTheRemainingTokens(p *parser) bool {
       
  2149 	return true
       
  2150 }
       
  2151 
  2117 const whitespaceOrNUL = whitespace + "\x00"
  2152 const whitespaceOrNUL = whitespace + "\x00"
  2118 
  2153 
  2119 // Section 12.2.6.5
  2154 // Section 12.2.6.5
  2120 func parseForeignContent(p *parser) bool {
  2155 func parseForeignContent(p *parser) bool {
  2121 	switch p.tok.Type {
  2156 	switch p.tok.Type {