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

:scope can't distinguish a context with no IDs nor classnames #96

Closed
b-fuze opened this issue Aug 18, 2023 · 1 comment
Closed

:scope can't distinguish a context with no IDs nor classnames #96

b-fuze opened this issue Aug 18, 2023 · 1 comment

Comments

@b-fuze
Copy link

b-fuze commented Aug 18, 2023

Here's a basic example that should work in a browser:

<html>
  <head>
    <script src="./nwsapi-2.2.7.js"></script>
    <script type="module">
      const parent = document.querySelector("div");
      console.log("NWSAPI", [...NW.Dom.select(":scope > div", parent)].map(d => d.className));
      console.log("NATIVE", [...parent.querySelectorAll(":scope > div")].map(d => d.className));
    </script>
  </head>
  <body>
    <div>
      <div class=outer>
        <div class=inner></div>
      </div>
      <div class=other-outer></div>
    </div>
  </body>
</html>

The output that I get:

NWSAPI Array [ "outer", "inner", "other-outer" ]
NATIVE Array [ "outer", "other-outer" ]

NWSAPI incorrectly selects the div with the inner classname while the browser correctly excludes that div, since it's not a direct child of the parent/context div.

The bug is due to makeref relying on classnames and/or ID's to distinguish the parent/context element from the children

@dperini
Copy link
Owner

dperini commented Jan 27, 2025

@b-fuze
can now build references for :scope through any of id, class, tagname, attributes in commit 6027080
Adding escape() to ids and class names will improve support for extra chars but this was another issue
Please test and report any trouble, and reopen in case fix still incomplete.

@dperini dperini closed this as completed Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants