Skip to content

Commit

Permalink
Merge pull request #146 from matejsuchanek/unicode
Browse files Browse the repository at this point in the history
Add unicode modifier to regex
  • Loading branch information
itamargiv authored Aug 20, 2020
2 parents 0ce1e1f + e1a1831 commit ba9704f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="103" />
<property name="lineLimit" value="102" />
</properties>
</rule>

Expand Down
3 changes: 2 additions & 1 deletion src/ValueParsers/YearMonthTimeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function __construct(
protected function stringParse( $value ) {
// Matches year and month separated by a separator.
// \p{L} matches letters outside the ASCII range.
if ( !preg_match( '/^(-?[\d\p{L}]+)\s*?[\/\-\s.,]\s*(-?[\d\p{L}]+)$/', trim( $value ), $matches ) ) {
$regex = '/^(-?[\d\p{L}]+)\s*?[\/\-\s.,]\s*(-?[\d\p{L}]+)$/u';
if ( !preg_match( $regex, trim( $value ), $matches ) ) {
throw new ParseException( 'Failed to parse year and month', $value, self::FORMAT_NAME );
}
list( , $a, $b ) = $matches;
Expand Down
6 changes: 6 additions & 0 deletions tests/ValueParsers/YearMonthTimeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ protected function getInstance() {
->will( $this->returnValue( array(
'January' => 1,
'Jan' => 1,
// to test Unicode (it's Czech)
'Březen' => 3,
'April' => 4,
'June' => 6,
) ) );
Expand Down Expand Up @@ -96,6 +98,10 @@ public function validInputProvider() {
'jan/1999' =>
array( '+1999-01-00T00:00:00Z' ),

// Unicode
'Březen 1999' => array( '+1999-03-00T00:00:00Z' ),
'březen 1999' => array( '+1999-03-00T00:00:00Z' ),

// use different date separators
'1-1999' =>
array( '+1999-01-00T00:00:00Z' ),
Expand Down

0 comments on commit ba9704f

Please sign in to comment.