Skip to content

Conversation

@klausi
Copy link
Contributor

@klausi klausi commented Oct 3, 2016

For issue #702 .

The pipe operator can appear in many places - a regex is too primitive, we need to actually parse the XPath expression.

This also uncovered a bug in the XPath expressions used for testing which contain a double single quote, which would be a broken XPath expression.

}

// Split any unions into individual expressions.
foreach (preg_split(self::UNION_PATTERN, $xpath) as $expression) {

Choose a reason for hiding this comment

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

self::UNION_PATTERN constant should be removed too. Or is used in other places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is used further above and for backwards compatibility reasons we should not remove it, other libraries might rely on it.

@klausi
Copy link
Contributor Author

klausi commented Oct 3, 2016

How do I see what failed on Scrutinizer? It just tells me that one failure condition exists, but no details?

*
* @return string[]
*/
protected function splitUnionParts($xpath)
Copy link
Member

Choose a reason for hiding this comment

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

should be private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

// Split any unions into individual expressions. We need to iterate
// through the string to correctly parse opening/closing quotes and
// braces which is not possible with regular expressions.
$union_parts = array();
Copy link
Member

Choose a reason for hiding this comment

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

please use camelCase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

'containing pipe' => array(
'some_xpath',
"some_tag[(contains(normalize-space(string(.)), 'foo|bar') | other_tag[contains(./@some_attribute, 'foo|bar')])]",
"some_xpath/some_tag[(contains(normalize-space(string(.)), 'foo|bar') | other_tag[contains(./@some_attribute, 'foo|bar')])]",
Copy link
Member

Choose a reason for hiding this comment

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

wrong expectation. Should be some_xpath/other_tag for the second part of the union

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, that's the question: the original regex suggests that within square brackets expressions should not be prefixed. Are you saying that we should also change the 'complex condition' test case further above to produce a different result?

Copy link
Member

Choose a reason for hiding this comment

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

ah sorry, I missed the fact it was inside square braces

@klausi
Copy link
Contributor Author

klausi commented Oct 5, 2016

While we wait for feedback here I'm now integrating my Mink fork in our PHPUnit initiative development branch for Drupal klausi/drupal@9db23a2

// braces which is not possible with regular expressions.
$unionParts = array();
$singleQuoteOpen = false;
$doubleQuoteOpen = false;
Copy link
Member

Choose a reason for hiding this comment

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

I would name them $inSingleQuotedString and $inDoubleQuotedString. It would better reflect their usage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

$bracketOpen = 0;
$lastUnion = 0;
for ($i = 0; $i < strlen($xpath); $i++) {
if ($xpath{$i} === "'" && $doubleQuoteOpen === false) {
Copy link
Member

Choose a reason for hiding this comment

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

Please use ! instead of === false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

for ($i = 0; $i < strlen($xpath); $i++) {
if ($xpath{$i} === "'" && $doubleQuoteOpen === false) {
if ($singleQuoteOpen === true) {
$singleQuoteOpen = false;
Copy link
Member

Choose a reason for hiding this comment

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

can be simplified: $singleQuoteOpen = !$singleQuoteOpen

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

} else {
$singleQuoteOpen = true;
}
} else if ($xpath{$i} === '"' && $singleQuoteOpen === false) {
Copy link
Member

Choose a reason for hiding this comment

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

should be elseif without space to match our coding standards

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

$doubleQuoteOpen = true;
}
} else if ($singleQuoteOpen === false && $doubleQuoteOpen === false) {
if ($xpath{$i} === '[') {
Copy link
Member

Choose a reason for hiding this comment

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

please use $xpath[$i] rather than $xpath{$i} to access the element.

And I think defining a $char variable may be more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

$unionParts = array();
$singleQuoteOpen = false;
$doubleQuoteOpen = false;
$bracketOpen = 0;
Copy link
Member

Choose a reason for hiding this comment

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

$bracketLevel or $openedBrackets would be a better name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@claudiu-cristea
Copy link

claudiu-cristea commented Oct 10, 2016

@klausi, looks good, better than trying with regexp. That seems to be an impossible try. When this gets committed we need only to refresh composer.lock in https://www.drupal.org/node/2808085

@stof stof merged commit 39e3309 into minkphp:master Oct 14, 2016
@stof
Copy link
Member

stof commented Oct 14, 2016

thanks @klausi

@stof
Copy link
Member

stof commented Oct 18, 2016

FYI, the discussion on the related Symfony BrowserKit PR highlighted the high performance impact of this change. So I'm looking at the progress on the alternate implemented proposed by @nicolas-grekas in symfony/symfony#20235 before making a Mink release (to use it instead if appropriate)

@klausi klausi mentioned this pull request Nov 2, 2016
mxr576 pushed a commit to tamasd/Mink that referenced this pull request May 3, 2019
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.

3 participants