Skip to content

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

@tom-mayer

Description

@tom-mayer

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.

Metadata

Metadata

Assignees

Labels

bugA confirmed bug, that we should fixfixedAn {bug|improvement} that has been {fixed|implemented}

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions