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

XpathElementSpecification cannot match text containing single quotes #2

Open
crafds1234 opened this issue Jun 28, 2021 · 0 comments
Open

Comments

@crafds1234
Copy link

E.g. this spec fails

anElement().withText("Some text with 'ABC' quoted with single quotes")

with this error:

InvalidSelectorError: Unable to locate an element with the xpath expression //*[text() = 'Some text with 'ABC' quoted with single quotes'] because of the following error:
SyntaxError: The expression is not a legal expression.

On inspection of com.lmax.elementspec.XPathElementSpecification#withText :

appendCondition("text() = '" + text + "'")

The code could detect single/double quotes and use the 'other' quote to quote the string for the test.

The XPath Recommendation (http://www.w3.org/TR/xpath) states:

 Literal ::=   '"' [^"]* '"' 
            | "'" [^']* "'"

So it is impossible to test a single string that contains both types of quotes without complex construction of the test string by concat-ing litertals; e.g.:

*[@text = concat('"', "'")]

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

1 participant