code4craft / code4craft/xsoup

And condition does not work if arguments are reversed.

Open
#46 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
474
Forks
148
PR merge metrics
No merged PRs in 30d

Description

Hi,

I have found that the xpath

//div[@data-hveid and @class='g']

does not work, returns 0 elements

but the xpath

//div[@class='g' and @data-hveid]

does work, returning 1 element. The code example is below (jsoup 1.11.3, xsoup 0.3.1).

`

	String html = "<!DOCTYPE html>" +
		"<html>" +
		"  <head>" +
		"    <title>test</title>" +
		"  </head>" +
		"  <body>" +
		"  <div class=\"g\" data-hveid=\"CAYQAA\">" +
		"  </div>" +
		"  </body>" +
		"</html>";
	Document document = Jsoup.parse(html);

	// does not work
	String xpath = "//div[@data-hveid and @class='g']";

	// does work
	//String xpath = "//div[@class='g' and @data-hveid]";

	XElements elements = Xsoup.compile(xpath).evaluate(document);
	System.out.println(elements.getElements().size());

	for (Element element : elements.getElements())
	{
	  System.out.println(element.toString());
	}

`

I think it should work both ways.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Java reproduction using Jsoup.parse, Xsoup.compile, and XElements.evaluate. Compare the two XPath predicate orders and trace the parser or evaluator behavior that produces different results. Done means both expressions return the same matching div, with a regression test covering the reversed conditions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.