Skip to content

Commit c40510e

Browse files
Merge pull request #9 from bz-projects/v-4
added v.4.0
2 parents f2477c7 + b6413f2 commit c40510e

10 files changed

Lines changed: 111 additions & 51 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
}
1313
],
1414
"require": {
15-
"enshrined/svg-sanitize": "^0.21.0"
15+
"enshrined/svg-sanitize": "^0.22.0"
1616
}
1717
}

composer.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

easy-svg.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Easy SVG Support
44
Plugin URI: https://wordpress.org/plugins/easy-svg/
55
Description: Add SVG Support for WordPress.
6-
Version: 3.9
6+
Version: 4.0
77
Author: Benjamin Zekavica
88
Requires PHP: 8.0
99
Requires at least: 6.0

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Tags: svg, svg support, upload svg, svg media, easy-svg
66
Requires at least: 6.0
77
Tested up to: 6.8
88
Requires PHP: 8.0
9-
Stable tag: 3.9
9+
Stable tag: 4.0
1010
License: GPLv3
1111
License URI: http://www.gnu.org/licenses/gpl-3.0.txt
1212

@@ -81,6 +81,10 @@ Please check out my repository on Github:
8181

8282

8383
== Changelog ==
84+
= 4.0: September 2, 2025 =
85+
* Support for new WordPress version
86+
* Support Gutenberg Version
87+
* Updated SVG Sanitizer Package
8488

8589
= 3.9: 1st of April, 2025 =
8690
* Support for new WordPress version 6.8

vendor/autoload.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
echo $err;
1515
}
1616
}
17-
trigger_error(
18-
$err,
19-
E_USER_ERROR
20-
);
17+
throw new RuntimeException($err);
2118
}
2219

2320
require_once __DIR__ . '/composer/autoload_real.php';

vendor/composer/InstalledVersions.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,23 @@
2626
*/
2727
class InstalledVersions
2828
{
29+
/**
30+
* @var string|null if set (by reflection by Composer), this should be set to the path where this class is being copied to
31+
* @internal
32+
*/
33+
private static $selfDir = null;
34+
2935
/**
3036
* @var mixed[]|null
3137
* @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
3238
*/
3339
private static $installed;
3440

41+
/**
42+
* @var bool
43+
*/
44+
private static $installedIsLocalDir;
45+
3546
/**
3647
* @var bool|null
3748
*/
@@ -309,6 +320,24 @@ public static function reload($data)
309320
{
310321
self::$installed = $data;
311322
self::$installedByVendor = array();
323+
324+
// when using reload, we disable the duplicate protection to ensure that self::$installed data is
325+
// always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
326+
// so we have to assume it does not, and that may result in duplicate data being returned when listing
327+
// all installed packages for example
328+
self::$installedIsLocalDir = false;
329+
}
330+
331+
/**
332+
* @return string
333+
*/
334+
private static function getSelfDir()
335+
{
336+
if (self::$selfDir === null) {
337+
self::$selfDir = strtr(__DIR__, '\\', '/');
338+
}
339+
340+
return self::$selfDir;
312341
}
313342

314343
/**
@@ -322,19 +351,27 @@ private static function getInstalled()
322351
}
323352

324353
$installed = array();
354+
$copiedLocalDir = false;
325355

326356
if (self::$canGetVendors) {
357+
$selfDir = self::getSelfDir();
327358
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
359+
$vendorDir = strtr($vendorDir, '\\', '/');
328360
if (isset(self::$installedByVendor[$vendorDir])) {
329361
$installed[] = self::$installedByVendor[$vendorDir];
330362
} elseif (is_file($vendorDir.'/composer/installed.php')) {
331363
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
332364
$required = require $vendorDir.'/composer/installed.php';
333-
$installed[] = self::$installedByVendor[$vendorDir] = $required;
334-
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
335-
self::$installed = $installed[count($installed) - 1];
365+
self::$installedByVendor[$vendorDir] = $required;
366+
$installed[] = $required;
367+
if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
368+
self::$installed = $required;
369+
self::$installedIsLocalDir = true;
336370
}
337371
}
372+
if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
373+
$copiedLocalDir = true;
374+
}
338375
}
339376
}
340377

@@ -350,7 +387,7 @@ private static function getInstalled()
350387
}
351388
}
352389

353-
if (self::$installed !== array()) {
390+
if (self::$installed !== array() && !$copiedLocalDir) {
354391
$installed[] = self::$installed;
355392
}
356393

vendor/composer/installed.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
"packages": [
33
{
44
"name": "enshrined/svg-sanitize",
5-
"version": "0.21.0",
6-
"version_normalized": "0.21.0.0",
5+
"version": "0.22.0",
6+
"version_normalized": "0.22.0.0",
77
"source": {
88
"type": "git",
99
"url": "https://github.com/darylldoyle/svg-sanitizer.git",
10-
"reference": "5e477468fac5c5ce933dce53af3e8e4e58dcccc9"
10+
"reference": "0afa95ea74be155a7bcd6c6fb60c276c39984500"
1111
},
1212
"dist": {
1313
"type": "zip",
14-
"url": "https://api.github.com/repos/darylldoyle/svg-sanitizer/zipball/5e477468fac5c5ce933dce53af3e8e4e58dcccc9",
15-
"reference": "5e477468fac5c5ce933dce53af3e8e4e58dcccc9",
14+
"url": "https://api.github.com/repos/darylldoyle/svg-sanitizer/zipball/0afa95ea74be155a7bcd6c6fb60c276c39984500",
15+
"reference": "0afa95ea74be155a7bcd6c6fb60c276c39984500",
1616
"shasum": ""
1717
},
1818
"require": {
@@ -23,7 +23,7 @@
2323
"require-dev": {
2424
"phpunit/phpunit": "^6.5 || ^8.5"
2525
},
26-
"time": "2025-01-13T09:32:25+00:00",
26+
"time": "2025-08-12T10:13:48+00:00",
2727
"type": "library",
2828
"installation-source": "dist",
2929
"autoload": {
@@ -44,7 +44,7 @@
4444
"description": "An SVG sanitizer for PHP",
4545
"support": {
4646
"issues": "https://github.com/darylldoyle/svg-sanitizer/issues",
47-
"source": "https://github.com/darylldoyle/svg-sanitizer/tree/0.21.0"
47+
"source": "https://github.com/darylldoyle/svg-sanitizer/tree/0.22.0"
4848
},
4949
"install-path": "../enshrined/svg-sanitize"
5050
}

vendor/composer/installed.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'name' => 'benjaminzekavica/easy-svg',
44
'pretty_version' => 'dev-master',
55
'version' => 'dev-master',
6-
'reference' => '55fa71f309dbb75ab6fb96cf66a69097335e9f95',
6+
'reference' => 'f2477c7744d8c44c69f347357b146b9adcc4dca7',
77
'type' => 'library',
88
'install_path' => __DIR__ . '/../../',
99
'aliases' => array(),
@@ -13,16 +13,16 @@
1313
'benjaminzekavica/easy-svg' => array(
1414
'pretty_version' => 'dev-master',
1515
'version' => 'dev-master',
16-
'reference' => '55fa71f309dbb75ab6fb96cf66a69097335e9f95',
16+
'reference' => 'f2477c7744d8c44c69f347357b146b9adcc4dca7',
1717
'type' => 'library',
1818
'install_path' => __DIR__ . '/../../',
1919
'aliases' => array(),
2020
'dev_requirement' => false,
2121
),
2222
'enshrined/svg-sanitize' => array(
23-
'pretty_version' => '0.21.0',
24-
'version' => '0.21.0.0',
25-
'reference' => '5e477468fac5c5ce933dce53af3e8e4e58dcccc9',
23+
'pretty_version' => '0.22.0',
24+
'version' => '0.22.0.0',
25+
'reference' => '0afa95ea74be155a7bcd6c6fb60c276c39984500',
2626
'type' => 'library',
2727
'install_path' => __DIR__ . '/../enshrined/svg-sanitize',
2828
'aliases' => array(),

vendor/composer/platform_check.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
2020
}
2121
}
22-
trigger_error(
23-
'Composer detected issues in your platform: ' . implode(' ', $issues),
24-
E_USER_ERROR
22+
throw new \RuntimeException(
23+
'Composer detected issues in your platform: ' . implode(' ', $issues)
2524
);
2625
}

vendor/enshrined/svg-sanitize/src/Sanitizer.php

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ protected function cleanAttributesOnWhitelist(\DOMElement $element)
421421
* Such as xlink:href when the xlink namespace isn't imported.
422422
* We have to do this as the link is still ran in this case.
423423
*/
424-
if (false !== strpos($attrName, 'href')) {
424+
if (false !== stripos($attrName, 'href')) {
425425
$href = $element->getAttribute($attrName);
426426
if (false === $this->isHrefSafeValue($href)) {
427427
$element->removeAttribute($attrName);
@@ -453,14 +453,17 @@ protected function cleanAttributesOnWhitelist(\DOMElement $element)
453453
*/
454454
protected function cleanXlinkHrefs(\DOMElement $element)
455455
{
456-
$xlinks = $element->getAttributeNS('http://www.w3.org/1999/xlink', 'href');
457-
if (false === $this->isHrefSafeValue($xlinks)) {
458-
$element->removeAttributeNS( 'http://www.w3.org/1999/xlink', 'href' );
459-
$this->xmlIssues[] = array(
460-
'message' => 'Suspicious attribute \'href\'',
461-
'line' => $element->getLineNo(),
462-
);
456+
foreach ($element->attributes as $attribute) {
457+
// remove attributes with unexpected namespace prefix, e.g. `XLinK:href` (instead of `xlink:href`)
458+
if ($attribute->prefix === '' && strtolower($attribute->nodeName) === 'xlink:href') {
459+
$element->removeAttribute($attribute->nodeName);
460+
$this->xmlIssues[] = array(
461+
'message' => sprintf('Unexpected attribute \'%s\'', $attribute->nodeName),
462+
'line' => $element->getLineNo(),
463+
);
464+
}
463465
}
466+
$this->cleanHrefAttributes($element, 'xlink');
464467
}
465468

466469
/**
@@ -470,13 +473,33 @@ protected function cleanXlinkHrefs(\DOMElement $element)
470473
*/
471474
protected function cleanHrefs(\DOMElement $element)
472475
{
473-
$href = $element->getAttribute('href');
474-
if (false === $this->isHrefSafeValue($href)) {
475-
$element->removeAttribute('href');
476-
$this->xmlIssues[] = array(
477-
'message' => 'Suspicious attribute \'href\'',
478-
'line' => $element->getLineNo(),
479-
);
476+
$this->cleanHrefAttributes($element);
477+
}
478+
479+
protected function cleanHrefAttributes(\DOMElement $element, string $prefix = ''): void
480+
{
481+
$relevantAttributes = array_filter(
482+
iterator_to_array($element->attributes),
483+
static function (\DOMAttr $attr) use ($prefix) {
484+
return strtolower($attr->name) === 'href' && strtolower($attr->prefix) === $prefix;
485+
}
486+
);
487+
foreach ($relevantAttributes as $attribute) {
488+
if (!$this->isHrefSafeValue($attribute->value)) {
489+
$element->removeAttribute($attribute->nodeName);
490+
$this->xmlIssues[] = array(
491+
'message' => sprintf('Suspicious attribute \'%s\'', $attribute->nodeName),
492+
'line' => $element->getLineNo(),
493+
);
494+
continue;
495+
}
496+
// in case the attribute name is `HrEf`/`xlink:HrEf`, adjust it to `href`/`xlink:href`
497+
if (!in_array($attribute->nodeName, $this->allowedAttrs, true)
498+
&& in_array(strtolower($attribute->nodeName), $this->allowedAttrs, true)
499+
) {
500+
$element->removeAttribute($attribute->nodeName);
501+
$element->setAttribute(strtolower($attribute->nodeName), $attribute->value);
502+
}
480503
}
481504
}
482505

0 commit comments

Comments
 (0)