Skip to content

Commit

Permalink
Add BC for PHP 7.2, see https://bugs.php.net/bug.php?id=73947
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jan 16, 2017
1 parent 238f6dd commit 3f723a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Pattern matching changelog

## ?.?.? / ????-??-??

## 7.1.1 / 2017-01-16

* Added BC for PHP 7.2: Empty optional patterns should not be NULLed
See https://bugs.php.net/bug.php?id=73947
(@thekid)

## 7.1.0 / 2016-08-29

* Added version compatibility with XP 8 - @thekid
Expand Down
10 changes: 9 additions & 1 deletion src/main/php/text/regex/MatchResult.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ static function __static() {
*/
public function __construct($length, $matches) {
$this->length= $length;
$this->matches= $matches;

// Ensure empty patterns are not NULLed to ensure BC.
// See https://bugs.php.net/bug.php?id=73947
foreach ($matches as $group => $match) {
$this->matches[$group]= [];
foreach ($match as $i => $segment) {
$this->matches[$group][$i]= (string)$segment;
}
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/test/php/text/regex/unittest/PatternTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,12 @@ public function stringCastWithFlag() {
public function stringCastWithFlags() {
$this->assertEquals('/end$/iU', (string)new Pattern('end$', Pattern::CASE_INSENSITIVE | Pattern::UNGREEDY));
}

#[@test]
public function php_bug_73947() {
$this->assertEquals(
['http://domain', 'http', '', 'domain'],
Pattern::compile('([a-z]+)://([^@]+@)?([a-z]+)')->match('http://domain')->group(0)
);
}
}

0 comments on commit 3f723a2

Please sign in to comment.