Page MenuHomePhabricator

Preview of global.js generates syntax error when "&" is in the content
Closed, DuplicatePublic

Description

When I load https://meta.wikimedia.org/w/index.php?title=User:Fomafix/global.js&action=edit and fill in

console.log( "foobar" );

and click on Preview then I see foobar in the JavaScript console.

But when I fill in

console.log( "foo&bar" );

and click on Preview then I see the error message

SyntaxError: expected expression, got '}'

and all JavaScript of the UI is missing.

Event Timeline

On the content

console.log('foobar');

the HTML of the preview contains

<script>(window.RLQ=window.RLQ||[]).push(function(){
mw.config.set({...}});
mw.loader.state({...});
mw.loader.implement("ext.globalCssJs.user@1xnrk9q",function($,jQuery,require,module){console.log('foobar');});
mw.loader.implement("user.options@03vsp6b",function($,jQuery,require,module){/*@nomin*/mw.user.options.set({...});
});
...
});</script>

On the content

console.log('foo&bar');

the HTML of the preview contains

<script>(window.RLQ=window.RLQ||[]).push(function(){
mw.config.set({...}});
mw.loader.state({...});
h(function(){mw.loader.implement("ext.globalCssJs.user@1q2pk0s",function($,jQuery,require,module){console.log('foo&bar');});});/*]]
mw.loader.implement("user.options@03vsp6b",function($,jQuery,require,module){/*@nomin*/mw.user.options.set({...});
});
...
});</script>

Problem also happens when a < is in the string.

This may be a problem with the MediaWiki-ResourceLoader.