-
-
Notifications
You must be signed in to change notification settings - Fork 857
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
feat: Support XPath2.0 to 3.1 #1774
Conversation
[Is XPath 3.1 100% upwardly compatible with XPath 2.0?](https://stackoverflow.com/a/62438044/20307768) [What are the differences between versions of XPath (1.0, 2.0, 3.1)](https://stackoverflow.com/a/51377660/20307768)
very cool, running tests now any chance you can add a test for something like just copy |
That is not correct because it passes here on github, so yeah, super important to add a tests or it cant be merged |
@Constantin1489 interesting
So it should throw an exception if the xpath string is invalid right? I wonder |
Okay, I do it. Please, give me few days |
Is there a method to run tests locally? Or is it just a port conflict? |
|
Yes, I did it before. I cannot configure it correctly.
I tried it on Rocky os 9(RHEL) it also failed.
|
I cant help there sorry, i never tried in mac or windows |
@dgtlmoon I added a 09b6203 test for the syntax. (#1774 (comment)). Explanations will be commented on there. |
|
||
res = client.post( | ||
url_for("edit_page", uuid="first"), | ||
data={"include_filters": "//*[contains(@class, 'sametext')]|//*[contains(@class, 'changetext')]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing with the union operator. The operator is supported since 1.0.
//*[contains(@class, 'sametext')]
//*[contains(@class, 'changetext')]
will parse like
<div class="sametext">Some text thats the same</div>
<div class="sametext">Some text thats the same</div>
<div class="changetext">Some new text</div>
<div class="changetext">Some new text</div>
But the operator//*[contains(@class, 'sametext')]|//*[contains(@class, 'changetext')]
will parse like this
<div class="sametext">Some text thats the same</div>
<div class="changetext">Some new text</div>
<div class="sametext">Some text thats the same</div>
<div class="changetext">Some new text</div>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that it affects existing xpaths that people have saved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. It won't. It is just an xpath syntax explanation. I didn't explain here enough. I'm sorry for slabs.
Let's say modified.html
contains the content below.
$cat modified.html
<html>
<body>
<p>Which is across multiple lines</p>
<div class="sametext">Some text thats the same</div>
<div class="changetext">Some new text</div>
<div class="sametext">Some text thats the same</div>
<div class="changetext">Some new text</div>
</body>
</html>
basex
is cli xpath parser.
If the user uses the XPath union syntax, the result is below.
$basex -i modified.html "//*[contains(@class, 'sametext')]|//*[matches(@class, 'changetext')]"
<div class="sametext">Some text thats the same</div>
<div class="changetext">Some new text</div>
<div class="sametext">Some text thats the same</div>
<div class="changetext">Some new text</div>
In your program, without the union syntax,
//*[contains(@class, 'sametext')]
//*[contains(@class, 'changetext')]
will show
<div class="sametext">Some text thats the same</div>
<div class="sametext">Some text thats the same</div>
<div class="changetext">Some new text</div>
<div class="changetext">Some new text</div>
) | ||
|
||
assert b"Some text thats the same" in res.data #in selector | ||
assert b"Some text that will change" in res.data #in selector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the include_filters contains //*[contains(@class, 'changetext')]
…ult early if it is not a list type.
4a75940
to
79cf984
Compare
@dgtlmoon I fixed problems only XPath2.0-3.1 related. If tests pass, it is okay to publish. |
…e and other XPath2.0-3.1 functions.
79cf984
to
20e2cde
Compare
@dgtlmoon please, review the new commit! |
@Constantin1489 I found a bug, when using |
wachete uses xpath2 also in their export #1922 |
2-2. 2-3.
|
Not sure I understand,
please just copy |
for 2-3. to validate for 3. Okay! |
I added! Would you please check what I missed? |
I just realised the VisualSelector needs checking if it still works with |
Sorry, I didn't understand. Would you explain it to me? |
See also, https://www.w3.org/TR/xpath20/#id-backwards-compatibility |
I think this is going to break functionality for atleast some people out there who have weird/tricky xPath1 selectors.. but CD absolutely needs xPath2/3 so we just have to soldier on :) |
I just got this :) |
@dgtlmoon that is a really great book. The author is one of the editors of XSLT2.0, 3.0 spec in W3C. He is also the editor of XPath2.0 reference of W3C! |
@Constantin1489 I think we can say that this went well in the end! thanks! havent got any large bug reports about problems caused by this |
@dgtlmoon the update_14 was a great choice! Thank you for your patience, too! |
@Constantin1489 over at - #2164 something changed in |
Thank you for the report. I will contact the repo. |
I've just tested |
@Constantin1489 amazing thank you :) |
Is XPath 3.1 100% upwardly compatible with XPath 2.0?
What are the differences between versions of XPath (1.0, 2.0, 3.1)
This update allows syntax like this below.(matches and position)
//*[matches(@id,"container")]/section[1]/article[2]/div[2]/table/tbody/tr[position()>3]/td[2]/a[1]
I tested with mine, works well.
However, exception catches and so on need to be added. Because I can't test every syntax or exception handling for this app.ex)(The issue in the image is fixed)
Also because of incompatibility between XPathes(1.0 vs 2.0), something will work differently.
Also,
I didn't do tests in the directory, because the tests already failed before I made changes.BTW, I tested this patch with mine, works well.Closes #1631
Closes #1674
#1773