CSSMin: Don't match empty string as remappable url
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 4 Apr 2018 20:07:33 +0000 (21:07 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 4 Apr 2018 20:17:35 +0000 (21:17 +0100)
commit5385f56e96bd76eb6aa2c46b6d4de6a8649aa85d
tree464933f1c0ba005ac0eb2dcb3d99674ef18a7c86
parentbb683d51765a4eb6443c02bc39ed5bae89a4b06a
CSSMin: Don't match empty string as remappable url

The empty string being matched causes an undefined array index
notice in production, seen from various random gadgets, but spiked
after a change in MonoBook from last week that introduced a
broken background-image rule with empty string as url.

In browsers, that is actually interpreted as valid and "expands"
to the current url and re-fetches as Accept:image/*, silly, but
still broken. The broken icon was fixed in MonoBook, but we still
need to avoid trying to remap empty string as url.

Two changes:

1. Fix regex used by remap() to not match empty string.
   This was already fixed for the 'url()' case without the
   optional quotes, but with quotes, it was being matched as
   non-empty. This is now fixed by using '+' instead of '*'.
   Added tests to confirm they produce output, and PHPUnit
   is configured to also assert no Notices are emitted (which
   it converts to fatal exceptions).

2. Fix processUrlMatch() as sanity check to throw if the key
   is missing.

Bug: T191237
Change-Id: I0ada337b0b4ab73c80236367ff79c31bcd13aa7d
includes/libs/CSSMin.php
tests/phpunit/includes/libs/CSSMinTest.php