Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floki.HTMLParser.FastHtml fails to parse <noscript> properly when present in head. #580

Open
arun-muthuraman opened this issue Jul 2, 2024 · 0 comments
Labels

Comments

@arun-muthuraman
Copy link

arun-muthuraman commented Jul 2, 2024

Description

When there is a noscript tag with content present in the head, when parsed, FastHtml moves all the tags present after noscript and the children of noscript into the body node. There is no issue if the noscript tag is present inside the body.

To Reproduce

Steps to reproduce the behavior:

  • Using Floki v0.35.2
  • Using Elixir v1.15.7
  • Using Erlang OTP 26
  • With this code:
 test_html =
  """
  <html>
   <head>
     <noscript><a href='/test'>link</a></noscript>
     <title>test</title>
   </head>
   <body>
     <noscript><a href='/test'>link</a></noscript>
     <p>test p</p>
   </body>
  </html>
  """

Floki.parse_document!(test_html, html_parser: Floki.HTMLParser.FastHtml)

[
  {"html", [],
   [
     {"head", [], ["\n   ", {"noscript", [], []}]},
     {"body", [],
      [
        {"a", [{"href", "/test"}], ["link"]},
        "\n   ",
        {"title", [], ["test"]},
        "\n \n \n   ",
        {"noscript", [], [{"a", [{"href", "/test"}], ["link"]}]},
        "\n   ",
        {"p", [], ["test p"]},
        "\n \n\n"
      ]}
   ]}
]

Expected behavior

[
{"html", [],
 [
   {"head", [],
    [
      "\n",
      {"noscript", [],
       [{"a", [{"href", "/link"}], ["link text"]}]},
      {"title", [], ["test"]},
      "\n"
    ]},
   "\n",
   {"body", [],
    [
      "\n",
      {"noscript", [],
       [{"a", [{"href", "/link"}], ["link text"]}]},
      "\n",
      {"p", [], ["test p"]},
      "\n\n\n"
    ]}
 ]}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant