From: nicolasconnault Date: Thu, 16 Jul 2009 03:21:19 +0000 (+0000) Subject: MDL-19840 Fixed a bug in regex delimiter quoting X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5daf5d3589c7d1e351005971ce71096735939a0f;p=moodle.git MDL-19840 Fixed a bug in regex delimiter quoting --- diff --git a/lib/simpletest/testsimpletestlib.php b/lib/simpletest/testsimpletestlib.php index be95ac60f6..1f775e28b7 100644 --- a/lib/simpletest/testsimpletestlib.php +++ b/lib/simpletest/testsimpletestlib.php @@ -52,6 +52,11 @@ class ContainsTagWithAttribute_test extends UnitTestCase { $expectation = new ContainsTagWithAttribute('span', 'class', 'error'); $this->assertFalse($expectation->test('message')); } + + function test_link() { + $expectation = new ContainsTagWithAttribute('a', 'href', 'http://www.test.com'); + $this->assertTrue($expectation->test('Click Here')); + } } /** diff --git a/lib/simpletestlib.php b/lib/simpletestlib.php index feb674cfef..af83fb9b5e 100644 --- a/lib/simpletestlib.php +++ b/lib/simpletestlib.php @@ -209,8 +209,8 @@ class ContainsTagWithAttribute extends SimpleExpectation { } 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); } @@ -241,8 +241,8 @@ class ContainsTagWithContents extends SimpleExpectation { } 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); }