Uh oh!
There was an error while loading. Please reload this page.
DOMXPath::quote(string $str): string - #13456
Conversation
method to quote strings in XPath,
similar to PDO::quote() / mysqli::real_escape_string
sample usage: $xp->query("//span[contains(text()," . $xp->quote($string) . ")]")
the algorithm is derived from Robert Rossney's research into XPath quoting published at https://stackoverflow.com/a/1352556/1067003
(but using an improved implementation I wrote myself, originally for chrome-php/chrome#575 )Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
ndossche
left a comment
There was a problem hiding this comment.
Thanks for this patch! I just have some minor comments, it looks mostly good.
I think it's a useful addition that makes a lot of sense.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
requested in PR feedback :o
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
ndossche
left a comment
There was a problem hiding this comment.
2 more minor things and then it's good!
Thanks for your work.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| * @param string $string string to quote. | ||
| * @return string quoted string. | ||
| */ | ||
| function UserlandDOMXPathQuote(string $string): string |
There was a problem hiding this comment.
I wonder if it makes sense trying to add this to the fuzzer to see if it finds differences in behaviour?
There was a problem hiding this comment.
don't know what fuzzer you're talking about, but sounds good because if there is any difference, it's probably a bug in the C version 👍
There was a problem hiding this comment.
We could fuzz this, but it will be a bit cumbersome to write a specific driver for this. We could ask ourselves whether we want to do it generalised for all these kinds of quoting methods.
ndossche
left a comment
There was a problem hiding this comment.
Looks good, tests pass. Tonight I will throw this in a fuzzer to find crashes and merge it if it's fine. Thanks for your work!
ndossche
commented
Feb 22, 2024
I've let it fuzz to search for crashes for a while now. It tried about 23 million cases and all seems good. If anyone is interested, here's the fuzz harness: https://gist.github.com/nielsdos/44981a753808129b0222f3ef28429c69 Basically, I just copied the function's code and made some wrappers for necessary functionality or copied some stuff over from the Zend code into the harness. That way I can run it without having to start the interpreter, which is easier. |
method to quote strings in XPath,
similar to PDO::quote() / mysqli::real_escape_string()
sample usage:
some variant of this is useful in HTML scraping scenarios.
the algorithm is derived from Robert Rossney's research into XPath quoting published at https://stackoverflow.com/a/1352556/1067003 (but using an improved implementation I wrote myself, originally for chrome-php/chrome#575 )