Skip to content

Commit

Permalink
MDL-19840 Fixed a bug in regex delimiter quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed Jul 16, 2009
1 parent 2cf6dfe commit 5daf5d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/simpletest/testsimpletestlib.php
Expand Up @@ -52,6 +52,11 @@ function test_fails() {
$expectation = new ContainsTagWithAttribute('span', 'class', 'error');
$this->assertFalse($expectation->test('<span class="mismatch">message</span>'));
}

function test_link() {
$expectation = new ContainsTagWithAttribute('a', 'href', 'http://www.test.com');
$this->assertTrue($expectation->test('<a href="http://www.test.com">Click Here</a>'));
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/simpletestlib.php
Expand Up @@ -209,8 +209,8 @@ function __construct($tag, $attribute, $value, $message = '%s') {
}

function test($html) {
$regex = '/<' . preg_quote($this->tag) . self::ATTRSREGEX .
'(?:\s+' . preg_quote($this->attribute) . '\s*=\s*["\']' . preg_quote($this->value) . '["\'])' .
$regex = '/<' . preg_quote($this->tag, '/') . self::ATTRSREGEX .
'(?:\s+' . preg_quote($this->attribute, '/') . '\s*=\s*["\']' . preg_quote($this->value, '/') . '["\'])' .
self::ATTRSREGEX . '\s*>/';
return preg_match($regex, $html);
}
Expand Down Expand Up @@ -241,8 +241,8 @@ function __construct($tag, $content, $message = '%s') {
}

function test($html) {
$regex = '/<' . preg_quote($this->tag) . self::ATTRSREGEX . '\s*>' . preg_quote($this->content) .
'<\/' . preg_quote($this->tag) . '>/';
$regex = '/<' . preg_quote($this->tag, '/') . self::ATTRSREGEX . '\s*>' . preg_quote($this->content, '/') .
'<\/' . preg_quote($this->tag, '/') . '>/';
return preg_match($regex, $html);
}

Expand Down

0 comments on commit 5daf5d3

Please sign in to comment.