merged branch rdohms/html5-regexp (PR #5382)
Commits
-------
7503ec9
Issue #5307: HTML regexp when match is false
Discussion
----------
Issue #5307: HTML regexp when match is false
When match is false the html5 validation regexp should be either inverted or not added.
Since we are in RC added a fix where this is not added, but marked a @todo so that this
can be revisited and we try to inverse the regexp instead.
Discussed in #5307.
---------------------------------------------------------------------------
by bschussek at 2012-08-30T08:40:06Z
👍 once the CS issue is fixed.
---------------------------------------------------------------------------
by rdohms at 2012-08-30T09:23:57Z
Could swear that was the CS in PSR-1 or 2, anyway, fixed.
---------------------------------------------------------------------------
by fabpot at 2012-08-30T09:26:07Z
Can you squash your commits before I merge? Thanks.
---------------------------------------------------------------------------
by rdohms at 2012-08-30T09:54:26Z
@fabpot done.
This commit is contained in:
commit
2982e6e678
|
@ -63,12 +63,22 @@ class Regex extends Constraint
|
|||
* Example: /^[a-z]+$/ would be converted to [a-z]+
|
||||
* However, if options are specified, it cannot be converted
|
||||
*
|
||||
* Pattern is also ignored if match=false since the pattern should
|
||||
* then be reversed before application.
|
||||
*
|
||||
* @todo reverse pattern in case match=false as per issue #5307
|
||||
*
|
||||
* @link http://dev.w3.org/html5/spec/single-page.html#the-pattern-attribute
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function getNonDelimitedPattern()
|
||||
{
|
||||
// If match = false, pattern should not be added to HTML5 validation
|
||||
if (!$this->match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match('/^(.)(\^?)(.*?)(\$?)\1$/', $this->pattern, $matches)) {
|
||||
$delimiter = $matches[1];
|
||||
$start = empty($matches[2]) ? '.*' : '';
|
||||
|
|
|
@ -162,6 +162,13 @@ class RegexValidatorTest extends \PHPUnit_Framework_TestCase
|
|||
'pattern' => '/[a-z]+/',
|
||||
));
|
||||
$this->assertEquals('.*[a-z]+.*', $constraint->getHtmlPattern());
|
||||
|
||||
// Dropped because of match=false
|
||||
$constraint = new Regex(array(
|
||||
'pattern' => '/[a-z]+/',
|
||||
'match' => false
|
||||
));
|
||||
$this->assertNull($constraint->getHtmlPattern());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in New Issue