mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
Prevent undefined index warnings
In some languages the \w+ does not match the characters used when translating UTC and the regular expression attempting to match the timezone fails. Testing in prod wikis where this fails such as ne.wikipedia.org shows it still works, it just generates a more generic regular expression. Since the overall process still works acceptably on the wikis outputting warnings this patch just adds a guard to prevent the warning and does not attempt to fix the underlying issue. Bug: T76558 Change-Id: If8e1ddd2d642b042cc24c51d5ba5aa8b34bc9552
This commit is contained in:
parent
21d59e334b
commit
438a7d5bb4
|
@ -864,13 +864,16 @@ abstract class EchoDiscussionParser {
|
|||
$output = $exemplarTimestamp;
|
||||
$tzRegex = '/\s*\(\w+\)\s*$/';
|
||||
$tzMatches = array();
|
||||
preg_match( $tzRegex, $output, $tzMatches );
|
||||
$output = preg_replace( $tzRegex, '', $output );
|
||||
if ( preg_match( $tzRegex, $output, $tzMatches ) ) {
|
||||
$output = preg_replace( $tzRegex, '', $output );
|
||||
}
|
||||
$output = preg_quote( $output, '/' );
|
||||
$output = preg_replace( '/[^\d\W]+/u', '[^\d\W]+', $output );
|
||||
$output = preg_replace( '/\d+/u', '\d+', $output );
|
||||
|
||||
$output .= preg_quote( $tzMatches[0] );
|
||||
if ( $tzMatches ) {
|
||||
$output .= preg_quote( $tzMatches[0] );
|
||||
}
|
||||
|
||||
if ( !preg_match( "/$output/u", $exemplarTimestamp ) ) {
|
||||
throw new MWException( "Timestamp regex does not match exemplar" );
|
||||
|
|
Loading…
Reference in a new issue