Merge "SVGReader: Detect CSS animated SVGs"

This commit is contained in:
jenkins-bot 2023-11-07 23:19:47 +00:00 committed by Gerrit Code Review
commit 950252cd63
3 changed files with 38 additions and 0 deletions

View file

@ -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

View 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

View file

@ -141,6 +141,17 @@ class SVGReaderTest extends \MediaWikiIntegrationTestCase {
'translations' => []
],
],
[
"$base/css-animated.svg",
[
'width' => 100,
'height' => 100,
'originalWidth' => '100',
'originalHeight' => '100',
'animated' => true,
'translations' => []
],
],
];
}