servo / servo/html5ever

the tree builder will modify the original doc's dom structure when encounters a foreign tag that it doesn't expect

Open
#694 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.6k
Forks
288
Avg merge
2d 22h
Merged PRs (30d)
8

Description

The issue is found when test against wpt test: https://wpt.live//mathml/presentation-markup/mrow/semantics-003.html
Original:

  <p>
      annotation-xml 5: 
      <math>
          <semantics>
              <csymbol>Content MathML</csymbol>
              <annotation-xml encoding="application/xhtml+xml">
                  <html xmlns="http://www.w3.org/1999/xhtml">
                      <head>
                          <title>application/xhtml+xml</title>
                      </head>
                      <body>
                          <p>application/xhtml+xml</p>
                      </body>
                  </html>
              </annotation-xml>
              <annotation-xml encoding="application/mathml-presentation+xml">
                  <mtext>error</mtext>
              </annotation-xml>
              <annotation>error</annotation>
      </math>
  </p>
  <p>
      annotation-xml 6: 
      <math>
          <semantics>
              <csymbol>Content MathML</csymbol>
              <annotation-xml encoding="text/html">
                  <html>
                      <head>
                          <title>text/html</title>
                      </head>
                      <body>
                          <p>text/html</p>
                      </body>
                  </html>
              </annotation-xml>
              <annotation-xml encoding="application/mathml-presentation+xml">
                  <mtext>error</mtext>
              </annotation-xml>
              <annotation>error</annotation>
          </semantics>
      </math>
  </p>

rcdom's html2html output

<p>
    annotation-xml 5: 
    <math>
        <semantics>
            <csymbol>Content MathML</csymbol>
            <annotation-xml encoding="application/xhtml+xml">
                
                    
                        <title>application/xhtml+xml</title>
                    
                    
                        </annotation-xml></semantics></math></p><p>application/xhtml+xml</p>
                    
                
            
            <annotation-xml encoding="application/mathml-presentation+xml">
                <mtext>error</mtext>
            </annotation-xml>
            <annotation>error</annotation>
    
<p></p>
<p>
    annotation-xml 6: 
    <math>
        <semantics>
            <csymbol>Content MathML</csymbol>
            <annotation-xml encoding="text/html">
                
                    
                        <title>text/html</title>
                    
                    
                        </annotation-xml></semantics></math></p><p>text/html</p>
                    
                
            
            <annotation-xml encoding="application/mathml-presentation+xml">
                <mtext>error</mtext>
            </annotation-xml>
            <annotation>error</annotation>
        
    
<p></p>

The root cause looks to be that the tag is unexpected in the foreign content and the following function pop out the scope https://github.com/servo/html5ever/blob/main/html5ever/src/tree_builder/mod.rs#L1834

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the WPT case at https://wpt.live//mathml/presentation-markup/mrow/semantics-003.html and inspect the scope-handling function in html5ever/src/tree_builder/mod.rs around line 1834. Compare the original DOM with rcdom's html2html output, focusing on unexpected head and body tags in foreign content. Done means the tree builder preserves the original structure for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.