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

Changed selection behaviour after upgrading 1.6.1 -> 1.6.2 (Bug?) #2018

Closed
tom-mayer opened this issue Oct 24, 2023 · 2 comments
Closed

Changed selection behaviour after upgrading 1.6.1 -> 1.6.2 (Bug?) #2018

tom-mayer opened this issue Oct 24, 2023 · 2 comments
Assignees
Labels
bug Confirmed bug that we should fix fixed
Milestone

Comments

@tom-mayer
Copy link

Reproduction case:

We have a nested list that looks a bit like this:

<ul>
    <li> foo </li>
    <li> bar
        <ul>
            <li>baz</li>
            <li>blah</li>
        </ul>
    </li>
</ul>
 var listRoot = // this is an element containing the top level <ul>
assertThat(listRoot).isNotNull();
assertThat(listRoot.select("> li"))
  .isNotNull()
  .hasSize(2);

var li1 = listRoot.selectFirst("> li:nth-child(1)");
var li1ul = Objects.requireNonNull(li1).select("ul");
// as expected the first li does not have a ul so this is empty
assertThat(li1ul).isEmpty();

var li2 = listRoot.selectFirst("> li:nth-child(2)");
// the second li should have one ul with two nested li
var li2ulLi = Objects.requireNonNull(li2).select("ul > li");
// this fails because the actual size is 3
// it contains the two sub li plus the parent li2 on which the selection is done
assertThat(li2ulLi).hasSize(2);

Observed behaviour:

When selecting the ul > li children of of li2, li2 is contained in the result set additionally to the two sub li. Technically the selector ul > li also matches li2 but only if starting from the root of the document. Changing the selector for the sub li to > ul > li works and only the two sub li are selected.

Expeced behaviour:

Doing a (li2).select("ul > li") should start with li2 as the root element so the selection should not consider the parent of li2 for selection.

@jhy jhy self-assigned this Oct 24, 2023
@jhy jhy added the bug Confirmed bug that we should fix label Oct 24, 2023
@jhy jhy added this to the 1.17.1 milestone Oct 24, 2023
@jhy jhy closed this as completed in 2a4a9cf Oct 24, 2023
@jhy jhy added the fixed label Oct 24, 2023
@jhy
Copy link
Owner

jhy commented Oct 24, 2023

Thanks, good find! Fixed. Regressed in 1.16.1 -> 1.16.2 when the ImmediateParent evaluator was reimplemented as an ImmediateParentRun.

@tom-mayer
Copy link
Author

Cool, thx for the fast reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug that we should fix fixed
Projects
None yet
Development

No branches or pull requests

2 participants