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

Moved the escaping of the xpath locator to the NamedSelector #641

Merged
merged 1 commit into from
Feb 19, 2015

Conversation

stof
Copy link
Member

@stof stof commented Feb 4, 2015

The NamedSelector has no valid reason to expect receiving an escaped value for the XPath locator. Calling code has no reason to know that the locator will be inserted in an XPath query.
The NamedSelector still support passing an escaped value for BC reasons but this is deprecated.
The method SelectorsHandler::xpathLiteral has been deprecated as well.
Fixes #384

This allows fixing the issue in Mink 1.7 rather than only 2.0, which allows people to migrate their code progressively (which is better)

@stof stof added this to the 1.7 milestone Feb 4, 2015
@aik099
Copy link
Member

aik099 commented Feb 4, 2015

It looks like some kind of code variation from 2.0 branch, but don't understand how it correlates with other commits from #384 task, that were made in 2013 year.

@stof
Copy link
Member Author

stof commented Feb 4, 2015

@aik099 it is indeed a variation of the work done in stof@ebf26f8 for #542 but keeping a BC layer instead of forcing the upgrade. The 2.0 PR will then be updated to include only the removal of the BC layer.

@aik099
Copy link
Member

aik099 commented Feb 4, 2015

I like the direction we're going with the drivers to allow safe transition to Mink 2.0.

@stof
Copy link
Member Author

stof commented Feb 4, 2015

this one is not about drivers (#633 is enough for that) but about userland code (I think that after this change, the upgrade should be painless except for some very custom use cases)

@stof
Copy link
Member Author

stof commented Feb 4, 2015

@aik099 is it OK for you ?

*
* @return SelectorsHandler
*/
protected function getSelectorsHandler()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will surely break something within QA-Tools, once merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I need to do Escaper::escapeLiteral when I need to escape xpath instead of doing

$selectors_handler = $this->getSelectorsHandler();
$selectors_handler->xpathLiteral($text)

Was this Escaper class part of Mink 1.6 release? Looks like it was, because commit 5bff8b5, which added this class is shown below 1.6.0 tag.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what could bullet-proof way of detecting if used Mink does automatic locator escaping by NamedSelector or I need to manually escape it upfront? I'm asking because of https://github.com/qa-tools/qa-tools/blob/develop/library/QATools/QATools/HtmlElements/Element/Form.php#L86 construct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once Mink 1.7 is released, the easiest way would probably be to bump the dependency to Mink 1.7 (which autoescapes)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and yes, I should not remove this method for BC. It will be removed only in 2.0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aik099 you could use method_exists(NamedSelector::class, 'escapeLocator') to detect that this PR is included in the codebase if you want to keep the Mink 1.6 compatibility.

And when building your own Xpath, you should indeed use the Escaper class (which is available in 1.6.0)

The NamedSelector has no valid reason to expect receiving an escaped value
for the XPath locator. Calling code has no reason to know that the locator
will be inserted in an XPath query.
The NamedSelector still support passing an escaped value for BC reasons
but this is deprecated.
The method SelectorsHandler::xpathLiteral and
Element::getSelectorsHandler have been deprecated as well.
@stof stof force-pushed the escape_named_selector branch from ebf26f8 to e238faa Compare February 5, 2015 09:04
@stof
Copy link
Member Author

stof commented Feb 19, 2015

@aik099 anything else to do before the merge ?

@aik099
Copy link
Member

aik099 commented Feb 19, 2015

Nope. You can merge.

stof added a commit that referenced this pull request Feb 19, 2015
Moved the escaping of the xpath locator to the NamedSelector
@stof stof merged commit aab8ded into minkphp:master Feb 19, 2015
@stof stof deleted the escape_named_selector branch February 19, 2015 10:39
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

Successfully merging this pull request may close these issues.

NamedSelector::translateToXPath error on 'content' selector
2 participants