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
[BUGFIX] First-child and last-child selectors are broken #293
Conversation
c534bcf
to
ac48a3f
Compare
I've used the XPath equivalents as listed on https://en.wikibooks.org/wiki/XPath/CSS_Equivalents. @bramley: Could you please test this PR and also verify it by reading? |
The XPaths are not correct. The first-child one is selecting all elements that are the first child of their parent. Similarly the last-child is selecting all elements that are the last child of their parent. The Symfony css selector package generates this XPath for p:first-child
While that could be generated by the preg_replace, the XPath expression can be more complex so I don't think it is easy (or even possible) to process a general expression with a preg_replace, e.g. p.red:first-child generates
As there can be subtle differences between similar XPath expressions, I'm not sure it is a good idea to try to implement css to XPath conversion without having a good knowledge of both. Particularly as there is a proven package that already does that. Wouldn't it be better to treat this as "missing functionality" or as a bug and fix it by using the Symfony component? |
ac48a3f
to
88255a0
Compare
Hi @bramley, thanks for the remarks. I've fixed the code and added some tests that fail with the old version of the patch. Could you please re-review? Thanks! |
88255a0
to
e737432
Compare
Yes, this looks better.
and maybe change "matches not" to "does not match" |
e737432
to
972880a
Compare
972880a
to
9dcda08
Compare
@bramley Good catch! Like this (re-pushed)? |
Fixes #286