jenkins-bot has submitted this change and it was merged.

Change subject: Prevent undefined index warnings
......................................................................


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
---
M includes/DiscussionParser.php
1 file changed, 6 insertions(+), 3 deletions(-)

Approvals:
  BryanDavis: Looks good to me, but someone else must approve
  Mattflaschen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/DiscussionParser.php b/includes/DiscussionParser.php
index 99a610e..bb227d1 100644
--- a/includes/DiscussionParser.php
+++ b/includes/DiscussionParser.php
@@ -864,13 +864,16 @@
                $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" );

-- 
To view, visit https://gerrit.wikimedia.org/r/177249
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If8e1ddd2d642b042cc24c51d5ba5aa8b34bc9552
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to