Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don’t unlocalize month names without letters #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ValueParsers/MonthNameUnlocalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function unlocalize( $date ) {
if ( !is_string( $search ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is now redundant, isn't it? The key is either a string or an integer (that cannot be matched with the regex).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could remove it and use (string)$search below, but to me that seems less clear (and probably also slightly slower). I’d prefer to keep the separate condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let's keep it.

continue;
}
if ( !preg_match( '/\\p{L}/', $search ) ) {
// no letters in here (e.g. "1." for "jan"), do not use (might match day rather than month: T325988)
continue;
}

$unlocalized = str_replace( $search, $replace, $date, $count );

Expand Down
4 changes: 4 additions & 0 deletions tests/ValueParsers/MonthNameUnlocalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function localizedDateProvider() {
array( '2000', '2000', array(
'2' => 'February',
) ),
// And others (e.g. cs) just repeat the number of the month with punctuation
array( '5. 4. 1891', '5. 4. 1891', array(
'5.' => 'May',
) ),
);
}

Expand Down