Make WordPress Core

Opened 8 years ago

Closed 6 years ago

#34711 closed defect (bug) (worksforme)

date_i18n bug with format M-t

Reported by: liedekef's profile liedekef Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3.1
Component: Date/Time Keywords:
Focuses: Cc:

Description

If the format "M-t" is used, the preg_replace used in date_i18n:

$dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );

is not matching the first character (being "M" in this case), resulting in the month abbrev not being replaced (the other regex's are similar).
A small php script that reproduces this (the format string starts with "M" and the second time with " ", the regex is taken from date_i18n):

<?php
$dateformatstring="M-t";
$dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . "test", $dateformatstring );
print "WRONG result: ".$dateformatstring."\n";
$dateformatstring=" M-t";
$dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . "test", $dateformatstring );
print "Correct result: ".$dateformatstring."\n";
?>

Attachments (1)

date_i18n.php (1.5 KB) - added by pbearne 8 years ago.
start of unit test

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
8 years ago

  • Component changed from General to Date/Time

#2 @pbearne
8 years ago

looking at the code this not a problem and the incoming string has ' ' prefix

#3 @liedekef
8 years ago

If plugins call date_i18n() directly, this empty space as prefix is not a guarantee.

@pbearne
8 years ago

start of unit test

#4 @pbearne
8 years ago

The extra space, is added in the function before regx and then removed after

<?php
$dateformatstring = ' '.$dateformatstring;
.....
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );

not saying this is weird and maybe wrong

I can't see why we could create regx that doesn't need a leading space

I am working on a more complete set of unit tests and will post patch for that later

but this all work including your error

#5 @Rarst
6 years ago

I don't see a problem with regex, M-t works just fine for me as is right now.

Though I have noticed that specific locale might not have abbreviated month names, e.g. I see M replaced with Ukrainian locale, but not Russian as of right now.

This ticket was mentioned in Slack in #polyglots by rarst. View the logs.


6 years ago

#7 @Rarst
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I've opened a new issue for locale thing: #44472

Note: See TracTickets for help on using tickets.