Page MenuHomePhabricator

Gadget: JavaScript parsing sometimes fails for token containing 'å'
Closed, DuplicatePublic

Description

I have a gadget, where parsing fails because of a token containing 'å'.

Test case: https://sv.wiktionary.org/w/index.php?title=MediaWiki:Gadget-experiments.js&oldid=2951705
Line causing the error: var språkkod = getLanguageCode(språk); // RAD SOM ORSAKAR FEL
Error message: (from https://sv.wiktionary.org/w/load.php?debug=true&lang=sv&modules=ext.gadget.experiments&only=scripts&skin=vector)

/*
MediaWiki:Gadget-experiments.js
*/
mw.log.error("JavaScript parse error: Parse error: Illegal token in file 'MediaWiki:Gadget-experiments.js' on line 73");
mw.loader.state( {
    "ext.gadget.experiments": "ready"
} );

While debugging, I discovered that:

I will attempt to solve this problem for sv-wiktionary, but replacing special chars.

Event Timeline

Thanks for the great testcase!
./includes/resourceloader/ResourceLoaderModule.php: Xml::encodeJsVar( "JavaScript parse error: $err" ) . ");";
Tentatively setting MediaWiki-ResourceLoader (but might also be MediaWiki-Parser or MediaWiki-extensions-Gadgets or somewhere else in the stack?).

Krinkle subscribed.

@Skalman The use of these unicode characters has always been valid inside strings and other content holders. However, JavaScript program identifiers (e.g. variable names) were not allowed to contain these characters in ECMAScript JavaScript version 3.

This was rectified in ECMAScript 5 which all modern browsers now support. There is already a task to update the JS validation and minification pipeline to allow ES5 syntax. This was previously not done because we still supported older browsers.