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

Something strange with premises tag and querySelector() / querySelectorAll() #156

Closed
johnnyoshika opened this issue Sep 27, 2021 · 3 comments
Labels

Comments

@johnnyoshika
Copy link

johnnyoshika commented Sep 27, 2021

It seems the premises tag (or something similar like x-premises, etc) has some strange and unexpected behavior with querySelector() and querySelectorAll().

Example:

import { parse } from "node-html-parser";

const sample1 = parse(
  "<premises><color>Red</color><color>Green</color></premises>"
);
console.log(sample1.querySelectorAll("color").length); // 0

const sample2 = parse("<foo><color>Red</color><color>Green</color></foo>");
console.log(sample2.querySelectorAll("color").length); // 2

The only difference between sample1 and sample2 is that sample1 wraps the HTML in a premises tag, whereas sample 2 uses foo. Yet the query for the color tag yields different results.

Here's a Codesandbox example: https://codesandbox.io/s/node-html-parser-premises-k5z81?file=/src/index.js:43-210

@nonara
Copy link
Collaborator

nonara commented Sep 28, 2021

Thanks for the report + the repro!

Looks like it's getting treated as preformatted (pre tag). Seems there's some regex which matches against partial, instead of full, tag name.

Will have a look at correcting it this weekend. I believe as a temporary workaround, passing the following should work:

{
  blockTextElements: {
    script: true,
    noscript: true,
    style: true
  }
}

@nonara nonara added the bug label Sep 28, 2021
@johnnyoshika
Copy link
Author

That option did the trick: https://codesandbox.io/s/node-html-parser-premises-k5z81?file=/src/index.js

Please let me know when you cut a new release with this fix, as I'll update my projects with it. Thanks for the quick response!

This was referenced Sep 29, 2021
nonara added a commit to nonara/node-html-parser that referenced this issue Oct 3, 2021
taoqf#156 fixes taoqf#124)

Tags 'premises' is matched as 'pre', 'pstyle' as 'style', etc.
@nonara nonara closed this as completed in 6823349 Oct 10, 2021
@nonara
Copy link
Collaborator

nonara commented Oct 10, 2021

Corrected in v5

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

2 participants