From 7a9ac93e8d8ac75d82798bf0ded4297a6e4c1cc7 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Tue, 24 Sep 2024 12:50:38 -0400 Subject: [PATCH] Use `class` instead of `id` for scribunto errors This avoids having multiple HTML elements with the same `id` attribute when certain Scribunto errors reoccur more than once on the same page. Bug: T375539 Change-Id: I123a0f0046a616f63506f096651ae917bbc65cc5 --- includes/Hooks.php | 2 +- modules/ext.scribunto.errors.js | 8 ++++++-- tests/parser/luaParserTests.txt | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/includes/Hooks.php b/includes/Hooks.php index e48dd4c8..e66150b3 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -223,7 +223,7 @@ class Hooks implements $parserError = htmlspecialchars( $e->getMessage() ); // #iferror-compatible error element - return "" . + return "" . $parserError . ""; } } diff --git a/modules/ext.scribunto.errors.js b/modules/ext.scribunto.errors.js index 7330ac3e..12a9bcc3 100644 --- a/modules/ext.scribunto.errors.js +++ b/modules/ext.scribunto.errors.js @@ -1,11 +1,15 @@ ( () => { mw.hook( 'wikipage.content' ).add( () => { - const regex = /^mw-scribunto-error-(\w+)/; + const regex = /\bmw-scribunto-error-(\w+)\b/; let popup; $( '.scribunto-error' ).each( ( index, span ) => { - const matches = regex.exec( span.id ); + let matches = regex.exec( span.className ); + if ( matches === null ) { + // T375539: backward-compatibility with old cached HTML + matches = regex.exec( span.id ); + } if ( matches === null ) { mw.log( 'mw.scribunto.errors: regex mismatch!' ); return; diff --git a/tests/parser/luaParserTests.txt b/tests/parser/luaParserTests.txt index 108fec31..20c6916c 100644 --- a/tests/parser/luaParserTests.txt +++ b/tests/parser/luaParserTests.txt @@ -272,10 +272,10 @@ extension=ScribuntoErrors-5e10d413 cat=Pages_with_script_errors sort= extension[ScribuntoErrors-5e10d413]="

Script error: No such module \"foo\".

No further details are available.

" !! html/php -

Script error: No such module "foo". +

Script error: No such module "foo".

!! html/parsoid -

Script error: No such module "foo".

+

Script error: No such module "foo".

!! end !! test @@ -290,10 +290,10 @@ extension=ScribuntoErrors-d64a22ba cat=Pages_with_script_errors sort= extension[ScribuntoErrors-d64a22ba]="

Script error: The function \"blah\" does not exist.

No further details are available.

" !! html/php -

Script error: The function "blah" does not exist. +

Script error: The function "blah" does not exist.

!! html/parsoid -

Script error: The function "blah" does not exist.

+

Script error: The function "blah" does not exist.

!! end !! test