Commit graph

43 commits

Author SHA1 Message Date
Timo Tijhof
5385f56e96 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
2018-04-04 21:17:35 +01:00
Fomafix
5ca659b287 CSSMin: Trim whitespace from attribute selectors and url tokens
* Trim whitespaces after opening and before closing parentheses and
  brackets.
* Ensure by test case that the invalid "url (" will not become the
  valid "url(" by minification.

This change also prevents the parsing problem in Firefox 57.0
https://bugzilla.mozilla.org/1418152 which is fixed in Firefox 57.0.1.

Change-Id: I804477ba7c6363f0e964fc8c7c0bc74d2d4c1a0d
2018-02-22 23:41:14 +00:00
Volker E
cdf11dff65 CSSMin: Remove XML declaration from SVGs
Removing unnecessary XML declaration prolog when embedding SVGs
as data URI and adding more complex elements & attributes to test.

Bug: T175318
Change-Id: Ibec8c2ab498554a6ad33b4420ae6258dcc80fcdf
2018-01-11 19:28:15 -08:00
Volker E
239ea7fe9f CSSMin: Re-introduce whitespace mangling in embedded SVGs
Convert newlines and tabs to spaces (which can be unencoded),
and consolidate runs of multiple spaces into a single space.
Also remove any leading and trailing spaces that might result
(most files end in a newline, for example).
Follow-up to Iddc98332d. This was reverted as dependency for the
original issues causing patch, but works perfectly fine.

Bug: T175318
Change-Id: Ic25d73caeb42ba7a32ef304806d401047b5a1997
2018-01-09 17:35:22 +00:00
Umherirrender
255d76f2a1 build: Updating mediawiki/mediawiki-codesniffer to 15.0.0
Clean up use of @codingStandardsIgnore
- @codingStandardsIgnoreFile -> phpcs:ignoreFile
- @codingStandardsIgnoreLine -> phpcs:ignore
- @codingStandardsIgnoreStart -> phpcs:disable
- @codingStandardsIgnoreEnd -> phpcs:enable

For phpcs:disable always the necessary sniffs are provided.
Some start/end pairs are changed to line ignore

Change-Id: I92ef235849bcc349c69e53504e664a155dd162c8
2018-01-01 14:10:16 +01:00
VolkerE
bd370e658f Revert "CSSMin: Improve encoding of quotes in embedded SVGs"
This reverts commit 5e3165f008.

Bug: T176884
Change-Id: I8bd9af67aeb11cb478ba402205ce834b1bec17a7
2017-09-29 14:45:27 +01:00
Esanders
ae336d89ef Revert "CSSMin: Mangle whitespace in embedded SVGs"
This reverts commit dfd42d2653.

Bug: T176884
Change-Id: Iddc98332d0b5a31d3a1c56c14014a53a06393f21
2017-09-29 14:45:14 +01:00
Roan Kattouw
dfd42d2653 CSSMin: Mangle whitespace in embedded SVGs
Convert newlines and tabs to spaces (which can be unencoded),
and consolidate runs of multiple spaces into a single space.
Also remove any leading and trailing spaces that might result
(most files end in a newline, for example).

Bug: T175318
Change-Id: Ic66c6acb37079cae84dd80ab2d5f2c829cf2df96
2017-09-19 18:52:54 +00:00
Roan Kattouw
5e3165f008 CSSMin: Improve encoding of quotes in embedded SVGs
When a URL (data: or otherwise) contains quotes, don't wrap it in
double quotes (") but in single quotes ('). This then allows
us to unencode double quotes (") in the data URI embedding of SVGs.

Bug: T175318
Change-Id: I3e7eab64e1c3e82066014fb594f82d786983ce90
2017-09-19 18:04:27 +00:00
Roan Kattouw
a4631b92e7 Improve encoding of embedded SVGs
Unencode spaces, slashes, colons and equals signs.

Bug: T175318
Change-Id: Idebdfca8f93d5e090deba5bf5a256d7054e2d6c8
2017-09-14 11:39:57 -07:00
Timo Tijhof
da6235ce3a resourceloader: Fix @covers for CSSMin tests
Change-Id: Idb451d244fbdfbb218a56c2953298b7fe29ed3d4
2017-07-27 21:40:21 -07:00
jenkins-bot
4a5f646a7f Merge "CSSMin: Skip #default#behaviorName when detecting local files" 2017-07-24 19:49:32 +00:00
Julien Girault
032f0ce8cb CSSMin: Skip #default#behaviorName when detecting local files
Bug: T162973
Change-Id: If76869910f308f8a91c73f287e7e74c214f02e9b
2017-07-23 01:05:39 +02:00
Timo Tijhof
bb36c7b32a CSSMin: Support parenthesis and quotes in url references
Previously they were often being cut short due to the url pattern
ending at the first single quote, double quote or closing parenthesis
regardless of which of those started the url match.

Running benchmarkCSSMin.php before and after the change doesn't seem
produce consistent improvement or regression. Repeated runs with count=100
with and without this change both have a median between 2.6ms and 2.9ms
using PHP 5.6, and between 2.6ms and 2.8ms using HHVM 3.12.

Bug: T60473
Change-Id: I6d6a077ad76588f3ed81b1901a26b7e56d2157ee
2017-05-05 18:33:24 +00:00
Thiemo Mättig
549c1f6dd7 Add tests for CSSMin::getMimeType
Direct follow up for I1768646. The tests are copied from my patch
If985f33, with one important difference: Now the file extension always
wins. Mismatches are not fixed any more by this code. This is intended.
See the discussion at I1768646.

Change-Id: I06b873a808d58ae7e53272765b156ac0fa293c2c
2017-03-26 18:08:06 +02:00
James D. Forrester
1e9c361960 tests: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I46261416f7603558dceb76ebe695a5cac274e417
2017-02-21 02:14:34 +00:00
Bartosz Dziewoński
c48e061f67 CSSMin: Correctly avoid fallbacks when embedding SVG files
The check for file existence before checking its MIME type was
building the path incorrectly, causing this piece of code to always
think the file does not exist. (The code to actually embed the file
was correct.)

This was not caught by the tests before of a bug in the test code,
which cancelled out this one.

Bug: T100958
Change-Id: I4469079f41d48052d0a02f98bb1ed02407abd54c
2016-11-02 10:26:21 +01:00
Reedy
83fb19cb13 Swap the rest of array() -> []
Change-Id: I76a7259ed952a0673a1941f08b39b545211fba07
2016-03-30 22:04:58 +00:00
Bartosz Dziewoński
1decdbce53 CSSMin: Make isRemoteUrl and isLocalUrl really private, now that we can in PHP 5.5
Well, protected, because we want to have unit tests for them, apparently.

Change-Id: I734b88599e5860aa59a07a89cc5389eb73b48813
2016-02-17 15:50:08 +01:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Amir E. Aharoni
c50cbe48ab Fix remaining Generic.Files.LineLength failures
Except the ones for which there is no clear way to fix
because of T114213.

Bug: T102614
Change-Id: I94a1fc7c890c82a36f0b51e42d311585c275775c
2015-10-03 17:23:07 +00:00
jenkins-bot
4590c637f5 Merge "CSSMin: remove dot segments in relative local URLs" 2015-08-20 14:11:36 +00:00
Ori Livneh
3063e85248 CSSMin: version URLs based on content, not mtime
The content of these files is more stable than their mtimes, which change
every time we roll out a new branch. Because MD5 avalanches well[0], using
the first five hexadecimal digits is sufficient to ensure that the chance
of two successive versions colliding is improbably small (roughly one in a
million).

[0]: https://en.wikipedia.org/wiki/Avalanche_effect

Change-Id: I1bdf94c58786d2545311b238476b48217a5a60af
2015-08-17 15:22:07 -07:00
Ori Livneh
5844ebcd93 CSSMin: remove dot segments in relative local URLs
Call wfRemoveDotSegments() (if available) on relative local URLs, so that
relative dot segments are collapsed.

Change-Id: Icc1c23a2a7d96c869412965bd8c3730d3c3b3a53
2015-08-16 10:41:45 -07:00
Timo Tijhof
9a2e47d188 CSSMin: Add tests for isRemoteUrl and isLocalUrl
Change-Id: I5a84eb62eaac96d0dd7f7e27bf76f64e7d7657cf
2015-01-29 19:47:46 +00:00
Bartosz Dziewoński
bf3b97791b CSSMin: Don't generate double rules for IE < 8 when embedding SVG files
Bug: 71003
Change-Id: Ic232e8d62b164940003afdfe7cce9f964d7e9cbc
2014-09-30 21:19:58 +00:00
Bartosz Dziewoński
fa223d65d6 CSSMin: Do not base64-encode non-binary files when embedding
Do not base64-encode non-binary files (containing only whitespace and
printable ASCII characters, which matches sane SVG files).

For SVG files the percent-encoded URIs are actually slightly longer
than the base64-encoded ones (~10%), but compress a lot better
resulting on 15-20% less data to transfer after gzip compression.

(The effect is best seen on the 'oojs-ui' module, which consists
mostly of SVG icons – especially after commenting out everything other
than 'oojs-ui.svg.css'.)

I tried this for binary files too, just in case; but as expected, they
suffer from a noticeable size increase even with compression (~15%).

Bug: 67341
Change-Id: Iddaf863b6be98570a2bb8e606f13946a96345f65
2014-09-30 23:13:42 +02:00
Bartosz Dziewoński
4c01f8b2bc Make "/*@noflip*/ /*@embed*/" annotation work without CSSJanus hacks
This reverts most of commit 2d842f1425,
leaving only the test added in it, and reimplements the same
functionality better.

Instead of stripping /*@noflip*/ annotations in CSSJanus, which is
incompatible with other implementations that preserve it, extend
CSSMin to allow other CSS comments to be present before the
rule-global @embed annotation. (This required making the regex logic
in it even worse than it was, but it's actually slightly less terrible
than I expected it would be. Good thing we have tests!)

Bug: 69698
Change-Id: I58603ef64f7d7cdc6461b34721a4d6b15f15ad79
2014-09-23 22:47:54 +00:00
Stephan Gambke
3b1b2b0c33 Fix CSSMin url() remapping when comments in CSS contain curly braces
Remapping of url()s was thrown off if the CSS contained comments
with curly braces. To fix, replace all block comments (except @embed
directives) with placeholders before url() processing and swap them
back in afterwards. Patch also includes tests.

Bug: 60077
Change-Id: If18a93c17ea9bcd529f6a664aa2dcc51d4a37f38
2014-06-30 09:14:10 +00:00
Trevor Parscal
3e2fd810d2 Revert "Fix "CSSMin url() value remapping not working in certain obscure cases""
This reverts commit fa1053a16a.

Breaks CSS output, making the skin and extensions look unstyled.

Change-Id: I297150f775dd5559f91f2c9c25c64b134459c6b6
2014-06-10 22:04:40 +00:00
Stephan Gambke
fa1053a16a Fix "CSSMin url() value remapping not working in certain obscure cases"
This patch extends the regex used to find URLs by css block quote subpatterns.

Bug: 60077
Change-Id: Ife00d01b78c6369f20ffc49d20aa58e354a61ee7
2014-06-09 23:50:28 +02:00
Bartosz Dziewoński
b8c88afe59 CSSMin: Add tests for handling existing data: URIs
Just a sanity check inspired by bug 66112.

Change-Id: Iac60a1eb15b3ff60822a3f24f2511c4bc64c092a
2014-06-05 18:38:41 +02:00
Siebrand Mazeland
896bda7c85 Pass phpcs-strict on some test files (7/11)
Change-Id: Ia0ceea60e7ef43959f868378f3fcd463a3adf782
2014-04-24 18:27:12 +00:00
Bartosz Dziewoński
2c866d8e73 CSSMin: Correctly format 'url()' values with parentheses etc.
Introduce new static function, CSSMin::buildUrlValue.

Actually using such values in CSS does not work well because the
URL_REGEX is nowhere near good enough. :(

Change-Id: I04a7078dd0087bcb461fa5e5168c870d37c255f4
2013-12-11 22:22:59 +01:00
Bartosz Dziewoński
e36dcfa4c6 CSSMin: Change behavior for missing files
We would previously return the path to the local file on the
filesystem, which is useless in all cases and possibly a security
issue in some. Now we return the URL at which the file would be
accessible had it existed.

Also reordered the code around that part to make the control flow
clearer and added a test.

Change-Id: I1d5befb2ea385ae4d316c5d8c5d1fc092b64c4ff
2013-12-11 21:21:36 +01:00
Bartosz Dziewoński
3987b10b51 CSSMin: Fix remapOne() for URLs that are proto-relative or have query part
Bug: 58338
Change-Id: I836a2c054ae3edc07895b2388f4ec8663223347a
2013-12-11 20:58:28 +01:00
Bartosz Dziewoński
f3779e067f Rewrite CSSMin::remap to support multiple url() values in one rule
Each can be selectively embedded by placing the /* @embed */ comment
just before the url() value. /* @embed */ at the beginning of the rule
affects all url() values appearing in it.

Three changes in existing behavior for previously supported syntax:
* /* @embed */ comments are no longer preserved in output
* rules not terminated by semicolons are correctly supported
* spaces within url() values are correctly supported

Bug: 46757
Bug: 56514
Change-Id: If9082f553fa920c606f12093f39f4a163ebacc32
2013-11-29 18:23:33 +00:00
Bartosz Dziewoński
cdcf0d5ed7 More tests for CSSMin::remap
Also added commented-out tests which should work, but don't.
Making them work in subsequent patch If9082f55.

Change-Id: I65f62493e6d10e7e90af8844f8a26e3982d75f51
2013-11-29 18:19:23 +00:00
addshore
749599fc3c @covers tags for unit tests
Change-Id: I2b486b38326bf23bd379efba2142034e24c0745f
2013-10-24 18:22:57 +01:00
addshore
de7af7ac2c Fix scope on all /phpunit test methods
Change-Id: I3ce92463d485a0fb23e464e9a8059330f32d79af
2013-10-24 10:31:32 +02:00
Timo Tijhof
b36d883017 Tests: Make phpunit providers "public static".
Follows-up I9d2b148e57 (including phpunit/languages this time).

Bug: 46434
Change-Id: I30e5efcd88c516121c454676bd7a18f9b7c8fca6
2013-03-22 03:12:37 +01:00
Timo Tijhof
181c7cdc8e Clean and repair many phpunit tests (+ fix implied configuration)
This commit depends on the introduction of
MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4.

Various tests already set their globals, but forgot to restore
them afterwards, or forgot to call the parent setUp, tearDown...

Either way they won't have to anymore with setMwGlobals.

Consistent use of function characteristics:
* protected function setUp
* protected function tearDown
* public static function (provide..)

(Matching the function signature with PHPUnit/Framework/TestCase.php)

Replaces:
 * public function (setUp|tearDown)\(
 * protected function $1(

 * \tfunction (setUp|tearDown)\(
 * \tprotected function $1(

 * \tfunction (data|provide)\(
 * \tpublic static function $1\(

Also renamed a few "data#", "provider#" and "provides#" functions
to "provide#" for consistency. This also removes confusion where
the /media tests had a few private methods called dataFile(),
which were sometimes expected to be data providers.

Fixes:

TimestampTest often failed due to a previous test setting a
different language (it tests "1 hour ago" so need to make sure
it is set to English).

MWNamespaceTest became a lot cleaner now that it executes with
a known context. Though the now-redundant code that was removed
didn't work anyway because wgContentNamespaces isn't keyed by
namespace id, it had them was values...

FileBackendTest:
* Fixed: "PHP Fatal: Using $this when not in object context"

HttpTest
* Added comment about:
  "PHP Fatal: Call to protected MWHttpRequest::__construct()"
  (too much unrelated code to fix in this commit)

ExternalStoreTest
* Add an assertTrue as well, without it the test is useless
  because regardless of whether wgExternalStores is true or false
  it only uses it if it is an array.

Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-09 03:01:51 +02:00
Timo Tijhof
41759f322c PHP test suite for CSSMin
Change-Id: Ic9195614acfd616ccdff57cfc666aa4dfa71fb96
2012-06-20 14:28:09 +02:00