Merge "SVGReader: Detect CSS animated SVGs"
This commit is contained in:
commit
950252cd63
3 changed files with 38 additions and 0 deletions
|
|
@ -282,6 +282,16 @@ class SVGReader {
|
|||
}
|
||||
}
|
||||
switch ( $this->reader->localName ) {
|
||||
case 'style':
|
||||
$styleContents = $this->reader->readString();
|
||||
if (
|
||||
str_contains( $styleContents, 'animated' ) ||
|
||||
str_contains( $styleContents, '@keyframes' )
|
||||
) {
|
||||
$this->debug( "HOUSTON WE HAVE ANIMATION" );
|
||||
$this->metadata['animated'] = true;
|
||||
}
|
||||
break;
|
||||
case 'script':
|
||||
// Normally we disallow files with
|
||||
// <script>, but its possible
|
||||
|
|
|
|||
17
tests/phpunit/data/media/css-animated.svg
Normal file
17
tests/phpunit/data/media/css-animated.svg
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
|
||||
<defs>
|
||||
<style>
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
svg {
|
||||
animation: spin 5s linear infinite;
|
||||
}
|
||||
.acircle {
|
||||
opacity: 0.65;
|
||||
}
|
||||
</style>
|
||||
</defs>
|
||||
<circle class="acircle" cx="40" cy="40" r="30" stroke="red" fill="none"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 419 B |
|
|
@ -141,6 +141,17 @@ class SVGReaderTest extends \MediaWikiIntegrationTestCase {
|
|||
'translations' => []
|
||||
],
|
||||
],
|
||||
[
|
||||
"$base/css-animated.svg",
|
||||
[
|
||||
'width' => 100,
|
||||
'height' => 100,
|
||||
'originalWidth' => '100',
|
||||
'originalHeight' => '100',
|
||||
'animated' => true,
|
||||
'translations' => []
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue