Skip to content

Commit

Permalink
Correctly set $wgAutoCreateTempUser['matchPattern'] config in JS
Browse files Browse the repository at this point in the history
Why:

* $wgAutoCreateTempUser['matchPattern'] is set to null by default
* In util.js, isTemporaryUser throws an error if the matchPattern
  is null, because it expects an array of strings.
* This means that with the default config, a JavaScript error is
  thrown.

What:

* If matchPattern is null, set it to an array containing genPattern,
  which is the same as what RealTempUserConfig::__construct does in
  PHP.

Bug: T367108
Change-Id: I22d3eb223dcc549335a62c3bca51319e37528a81
  • Loading branch information
Tchanders committed Jun 21, 2024
1 parent 72580a3 commit 5bd32be
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions resources/src/mediawiki.util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,8 @@ var util = {
var matchPatterns = config.AutoCreateTempUser.matchPattern;
if ( typeof matchPatterns === 'string' ) {
matchPatterns = [ matchPatterns ];
} else if ( matchPatterns === null ) {
matchPatterns = [ config.AutoCreateTempUser.genPattern ];
}
for ( var i = 0; i < matchPatterns.length; i++ ) {
var autoCreateUserMatchPattern = matchPatterns[ i ];
Expand Down
11 changes: 11 additions & 0 deletions tests/qunit/resources/mediawiki.util/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,17 @@ QUnit.module( 'mediawiki.util', QUnit.newMwEnvironment( {
assert.strictEqual( util.isTemporaryUser( username[ 1 ] ), username[ 2 ] );
} );

QUnit.test.each( 'isTemporaryUser matchPattern null', {
'prefix mismatch': [ '*$1', 'Test', false, true ],
'prefix match': [ '*$1', '*Some user', true, true ]
}, ( assert, username ) => {
mw.util.setOptionsForTest( {
AutoCreateTempUser: { enabled: username[ 3 ], genPattern: username[ 0 ], matchPattern: null }
} );

assert.strictEqual( util.isTemporaryUser( username[ 1 ] ), username[ 2 ] );
} );

QUnit.test( 'isInfinity', ( assert ) => {
assert.true( util.isInfinity( 'indefinite' ) );
assert.true( util.isInfinity( 'infinite' ) );
Expand Down

0 comments on commit 5bd32be

Please sign in to comment.