Page MenuHomePhabricator

CSS minifier breaks multi‑line strings
Closed, DeclinedPublicBUG REPORT

Description

Sample code

A:

/**
 * Global styles
 */
@import url("https://meta.wikimedia.org/w/load.php?only=styles&modules\
=ext.globalCssJs.user.styles\
&user=ExE_Boss");

B:

/**
 * Global styles
 *
 * The CSS minifier is buggy, so we (ab)use that by (ab)using comments
 * where CSS expects a multiline string:
 * (this is normally a syntax error!)
 */
@import url(https://meta.wikimedia.org/w/load.php?only=styles&modules/*
*/=ext.globalCssJs.user.styles/*
*/&user=ExE_Boss);

Source: https://wikitech.wikimedia.org/wiki/User:ExE_Boss/common.css

Expected behaviour

A:

@import url("https://meta.wikimedia.org/w/load.php?only=styles&modules=ext.globalCssJs.user.styles&user=ExE_Boss");

B:

/* syntax error */

Actual behaviour

A:

@import url("https://meta.wikimedia.org/w/load.php?only=styles&modules\\ =ext.globalCssJs.user.styles\\ &user=ExE_Boss"); /* malformed URL */

B:

@import url(https://meta.wikimedia.org/w/load.php?only=styles&modules=ext.globalCssJs.user.styles&user=ExE_Boss);

Version

MediaWiki1.37.0-wmf.16 (b771890)
2021-07-28T18:05:45

See also

Event Timeline

@ExE-Boss Is there a specific requirement or benefit in terms of how the styles are applied, that leads you to break it over multiple lines in this way?

If not, then I would decline this and take note of the edge case in a documented "known limitations" section, with how to work-around it. These limitations are often in place to benefit significant performance savings through reduced complexity. (It is not currently the intention of CSSMin to support all possible valid CSS syntax.)

Krinkle triaged this task as Medium priority.

Change 711190 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/libs/Minify@master] Docs: Write down known limitations

https://gerrit.wikimedia.org/r/711190

Declining per the above, but as said, please do write back if this multi-line format is required for something (e.g. for compat or integration with something else).

Change 711190 merged by jenkins-bot:

[mediawiki/libs/Minify@master] docs: Write down known limitations

https://gerrit.wikimedia.org/r/711190