Opened 9 years ago
Closed 6 years ago
#34711 closed defect (bug) (worksforme)
date_i18n bug with format M-t
Reported by: | 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)
Change History (8)
#3
@
8 years ago
If plugins call date_i18n() directly, this empty space as prefix is not a guarantee.
#4
@
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
@
7 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.
looking at the code this not a problem and the incoming string has ' ' prefix