|
28 | 28 | */ |
29 | 29 | public class HtmlTreeBuilder extends TreeBuilder { |
30 | 30 | // tag searches. must be sorted, used in inSorted. HtmlTreeBuilderTest validates they're sorted. |
31 | | - // todo - tag search in scope might need to be properly namespace aware - https://html.spec.whatwg.org/#has-an-element-in-scope |
32 | | - static final String[] TagsSearchInScope = new String[]{ |
33 | | - "annotation-xml", "applet", "caption", "desc", "foreignObject", "html", "marquee", "mi", "mn", "mo", "ms", "mtext", "object", "table", "td", "template", "th", "title" // <- svg title |
| 31 | + static final String[] TagsSearchInScope = new String[]{ // a particular element in scope |
| 32 | + "applet", "caption", "html", "marquee", "object", "table", "td", "template", "th" |
34 | 33 | }; |
| 34 | + // math and svg namespaces for particular element in scope |
| 35 | + static final String[]TagSearchInScopeMath = new String[] { |
| 36 | + "annotation-xml", "mi", "mn", "mo", "ms", "mtext" |
| 37 | + }; |
| 38 | + static final String[]TagSearchInScopeSvg = new String[] { |
| 39 | + "desc", "foreignObject", "title" |
| 40 | + }; |
| 41 | + |
35 | 42 | static final String[] TagSearchList = new String[]{"ol", "ul"}; |
36 | 43 | static final String[] TagSearchButton = new String[]{"button"}; |
37 | 44 | static final String[] TagSearchTableScope = new String[]{"html", "table"}; |
@@ -681,13 +688,22 @@ private boolean inSpecificScope(String[] targetNames, String[] baseTypes, @Nulla |
681 | 688 | // don't walk too far up the tree |
682 | 689 | for (int pos = bottom; pos >= top; pos--) { |
683 | 690 | Element el = stack.get(pos); |
684 | | - final String elName = el.normalName(); |
685 | | - if (inSorted(elName, targetNames)) |
686 | | - return true; |
687 | | - if (inSorted(elName, baseTypes)) |
688 | | - return false; |
689 | | - if (extraTypes != null && inSorted(elName, extraTypes)) |
690 | | - return false; |
| 691 | + String elName = el.normalName(); |
| 692 | + // namespace checks - arguments provided are always in html ns, with this bolt-on for math and svg: |
| 693 | + String ns = el.tag().namespace(); |
| 694 | + if (ns.equals(NamespaceHtml)) { |
| 695 | + if (inSorted(elName, targetNames)) |
| 696 | + return true; |
| 697 | + if (inSorted(elName, baseTypes)) |
| 698 | + return false; |
| 699 | + if (extraTypes != null && inSorted(elName, extraTypes)) |
| 700 | + return false; |
| 701 | + } else if (baseTypes == TagsSearchInScope) { |
| 702 | + if (ns.equals(NamespaceMathml) && inSorted(elName, TagSearchInScopeMath)) |
| 703 | + return false; |
| 704 | + if (ns.equals(NamespaceSvg) && inSorted(elName, TagSearchInScopeSvg)) |
| 705 | + return false; |
| 706 | + } |
691 | 707 | } |
692 | 708 | //Validate.fail("Should not be reachable"); // would end up false because hitting 'html' at root (basetypes) |
693 | 709 | return false; |
|
0 commit comments