Skip to content

Commit

Permalink
bug #9970 [CssSelector] fixed numeric attribute issue (jfsimon)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.3 branch.

Discussion
----------

[CssSelector] fixed numeric attribute issue

This PR adds a cast from number to string when parsing a numeric attribute value.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9968

Commits
-------

613535a [CssSelector] fixed numeric attribute issue
  • Loading branch information
fabpot committed Jan 7, 2014
2 parents 0ebf99b + 613535a commit a5b4aad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/CssSelector/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ private function parseAttributeNode(Node\NodeInterface $selector, TokenStream $s
$stream->skipWhitespace();
$value = $stream->getNext();

if ($value->isNumber()) {
// if the value is a number, it's casted into a string
$value = new Token(Token::TYPE_STRING, (string) $value->getValue(), $value->getPosition());
}

if (!($value->isIdentifier() || $value->isString())) {
throw SyntaxErrorException::unexpectedToken('string or identifier', $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public function getParserTestData()
array('div#foobar', array('Hash[Element[div]#foobar]')),
array('div:not(div.foo)', array('Negation[Element[div]:not(Class[Element[div].foo])]')),
array('td ~ th', array('CombinedSelector[Element[td] ~ Element[th]]')),
array('.foo[data-bar][data-baz=0]', array("Attribute[Attribute[Class[Element[*].foo][data-bar]][data-baz = '0']]")),
);
}

Expand Down

0 comments on commit a5b4aad

Please sign in to comment.