This commit is contained in:
Javier Casares 2026-08-08 08:53:08 +00:00
commit 7d3fc1969d
44 changed files with 1776 additions and 295 deletions

2
vendor/autoload.php vendored
View file

@ -19,4 +19,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit062b6bfebe9519df3bcac54aafa83aec::getLoader();
return ComposerAutoloaderInitc097ca862608a882f291ae6b935e271c::getLoader();

View file

@ -185,6 +185,8 @@ return array(
'League\\CommonMark\\Extension\\Mention\\Mention' => $vendorDir . '/league/commonmark/src/Extension/Mention/Mention.php',
'League\\CommonMark\\Extension\\Mention\\MentionExtension' => $vendorDir . '/league/commonmark/src/Extension/Mention/MentionExtension.php',
'League\\CommonMark\\Extension\\Mention\\MentionParser' => $vendorDir . '/league/commonmark/src/Extension/Mention/MentionParser.php',
'League\\CommonMark\\Extension\\NormalizeHeadings\\NormalizeHeadingsExtension' => $vendorDir . '/league/commonmark/src/Extension/NormalizeHeadings/NormalizeHeadingsExtension.php',
'League\\CommonMark\\Extension\\NormalizeHeadings\\NormalizeHeadingsProcessor' => $vendorDir . '/league/commonmark/src/Extension/NormalizeHeadings/NormalizeHeadingsProcessor.php',
'League\\CommonMark\\Extension\\SmartPunct\\DashParser' => $vendorDir . '/league/commonmark/src/Extension/SmartPunct/DashParser.php',
'League\\CommonMark\\Extension\\SmartPunct\\EllipsesParser' => $vendorDir . '/league/commonmark/src/Extension/SmartPunct/EllipsesParser.php',
'League\\CommonMark\\Extension\\SmartPunct\\Quote' => $vendorDir . '/league/commonmark/src/Extension/SmartPunct/Quote.php',
@ -361,6 +363,7 @@ return array(
'Nette\\Utils\\AssertionException' => $vendorDir . '/nette/utils/src/Utils/exceptions.php',
'Nette\\Utils\\Callback' => $vendorDir . '/nette/utils/src/Utils/Callback.php',
'Nette\\Utils\\DateTime' => $vendorDir . '/nette/utils/src/Utils/DateTime.php',
'Nette\\Utils\\DateTimeImmutable' => $vendorDir . '/nette/utils/src/Utils/DateTimeImmutable.php',
'Nette\\Utils\\FileInfo' => $vendorDir . '/nette/utils/src/Utils/FileInfo.php',
'Nette\\Utils\\FileSystem' => $vendorDir . '/nette/utils/src/Utils/FileSystem.php',
'Nette\\Utils\\Finder' => $vendorDir . '/nette/utils/src/Utils/Finder.php',

View file

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit062b6bfebe9519df3bcac54aafa83aec
class ComposerAutoloaderInitc097ca862608a882f291ae6b935e271c
{
private static $loader;
@ -24,16 +24,16 @@ class ComposerAutoloaderInit062b6bfebe9519df3bcac54aafa83aec
require __DIR__ . '/platform_check.php';
spl_autoload_register(array('ComposerAutoloaderInit062b6bfebe9519df3bcac54aafa83aec', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitc097ca862608a882f291ae6b935e271c', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit062b6bfebe9519df3bcac54aafa83aec', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitc097ca862608a882f291ae6b935e271c', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit062b6bfebe9519df3bcac54aafa83aec::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitc097ca862608a882f291ae6b935e271c::getInitializer($loader));
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit062b6bfebe9519df3bcac54aafa83aec::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitc097ca862608a882f291ae6b935e271c::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View file

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit062b6bfebe9519df3bcac54aafa83aec
class ComposerStaticInitc097ca862608a882f291ae6b935e271c
{
public static $files = array (
'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
@ -243,6 +243,8 @@ class ComposerStaticInit062b6bfebe9519df3bcac54aafa83aec
'League\\CommonMark\\Extension\\Mention\\Mention' => __DIR__ . '/..' . '/league/commonmark/src/Extension/Mention/Mention.php',
'League\\CommonMark\\Extension\\Mention\\MentionExtension' => __DIR__ . '/..' . '/league/commonmark/src/Extension/Mention/MentionExtension.php',
'League\\CommonMark\\Extension\\Mention\\MentionParser' => __DIR__ . '/..' . '/league/commonmark/src/Extension/Mention/MentionParser.php',
'League\\CommonMark\\Extension\\NormalizeHeadings\\NormalizeHeadingsExtension' => __DIR__ . '/..' . '/league/commonmark/src/Extension/NormalizeHeadings/NormalizeHeadingsExtension.php',
'League\\CommonMark\\Extension\\NormalizeHeadings\\NormalizeHeadingsProcessor' => __DIR__ . '/..' . '/league/commonmark/src/Extension/NormalizeHeadings/NormalizeHeadingsProcessor.php',
'League\\CommonMark\\Extension\\SmartPunct\\DashParser' => __DIR__ . '/..' . '/league/commonmark/src/Extension/SmartPunct/DashParser.php',
'League\\CommonMark\\Extension\\SmartPunct\\EllipsesParser' => __DIR__ . '/..' . '/league/commonmark/src/Extension/SmartPunct/EllipsesParser.php',
'League\\CommonMark\\Extension\\SmartPunct\\Quote' => __DIR__ . '/..' . '/league/commonmark/src/Extension/SmartPunct/Quote.php',
@ -419,6 +421,7 @@ class ComposerStaticInit062b6bfebe9519df3bcac54aafa83aec
'Nette\\Utils\\AssertionException' => __DIR__ . '/..' . '/nette/utils/src/Utils/exceptions.php',
'Nette\\Utils\\Callback' => __DIR__ . '/..' . '/nette/utils/src/Utils/Callback.php',
'Nette\\Utils\\DateTime' => __DIR__ . '/..' . '/nette/utils/src/Utils/DateTime.php',
'Nette\\Utils\\DateTimeImmutable' => __DIR__ . '/..' . '/nette/utils/src/Utils/DateTimeImmutable.php',
'Nette\\Utils\\FileInfo' => __DIR__ . '/..' . '/nette/utils/src/Utils/FileInfo.php',
'Nette\\Utils\\FileSystem' => __DIR__ . '/..' . '/nette/utils/src/Utils/FileSystem.php',
'Nette\\Utils\\Finder' => __DIR__ . '/..' . '/nette/utils/src/Utils/Finder.php',
@ -460,9 +463,9 @@ class ComposerStaticInit062b6bfebe9519df3bcac54aafa83aec
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit062b6bfebe9519df3bcac54aafa83aec::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit062b6bfebe9519df3bcac54aafa83aec::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit062b6bfebe9519df3bcac54aafa83aec::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitc097ca862608a882f291ae6b935e271c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitc097ca862608a882f291ae6b935e271c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitc097ca862608a882f291ae6b935e271c::$classMap;
}, null, ClassLoader::class);
}

View file

@ -80,17 +80,17 @@
},
{
"name": "league/commonmark",
"version": "2.8.2",
"version_normalized": "2.8.2.0",
"version": "2.9.0",
"version_normalized": "2.9.0.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/commonmark.git",
"reference": "59fb075d2101740c337c7216e3f32b36c204218b"
"reference": "5703d83ba3da3b2e356a5fedc848ed6d8ffb6529"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/59fb075d2101740c337c7216e3f32b36c204218b",
"reference": "59fb075d2101740c337c7216e3f32b36c204218b",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/5703d83ba3da3b2e356a5fedc848ed6d8ffb6529",
"reference": "5703d83ba3da3b2e356a5fedc848ed6d8ffb6529",
"shasum": ""
},
"require": {
@ -112,8 +112,8 @@
"github/gfm": "0.29.0",
"michelf/php-markdown": "^1.4 || ^2.0",
"nyholm/psr7": "^1.5",
"phpstan/phpstan": "^1.8.2",
"phpunit/phpunit": "^9.5.21 || ^10.5.9 || ^11.0.0",
"phpstan/phpstan": "^2.0.0",
"phpunit/phpunit": "^9.5.21 || ^10.5.9 || ^11.0.0 || ^12.0.0 || ^13.0.0",
"scrutinizer/ocular": "^1.8.1",
"symfony/finder": "^5.3 | ^6.0 | ^7.0 || ^8.0",
"symfony/process": "^5.4 | ^6.0 | ^7.0 || ^8.0",
@ -124,11 +124,11 @@
"suggest": {
"symfony/yaml": "v2.3+ required if using the Front Matter extension"
},
"time": "2026-03-19T13:16:38+00:00",
"time": "2026-08-03T13:42:31+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "2.9-dev"
"dev-main": "2.10-dev"
}
},
"installation-source": "dist",
@ -345,17 +345,17 @@
},
{
"name": "nette/utils",
"version": "v4.1.4",
"version_normalized": "4.1.4.0",
"version": "v4.1.5",
"version_normalized": "4.1.5.0",
"source": {
"type": "git",
"url": "https://github.com/nette/utils.git",
"reference": "7da6c396d7ebe142bc857c20479d5e70a5e1aac7"
"reference": "b043439dbdf954e6c28b5ea7e34b0100f83165e0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/utils/zipball/7da6c396d7ebe142bc857c20479d5e70a5e1aac7",
"reference": "7da6c396d7ebe142bc857c20479d5e70a5e1aac7",
"url": "https://api.github.com/repos/nette/utils/zipball/b043439dbdf954e6c28b5ea7e34b0100f83165e0",
"reference": "b043439dbdf954e6c28b5ea7e34b0100f83165e0",
"shasum": ""
},
"require": {
@ -375,13 +375,13 @@
},
"suggest": {
"ext-gd": "to use Image",
"ext-iconv": "to use Strings::webalize(), toAscii(), chr() and reverse()",
"ext-iconv": "to use Strings::chr(), ord() and reverse()",
"ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()",
"ext-json": "to use Nette\\Utils\\Json",
"ext-mbstring": "to use Strings::lower() etc...",
"ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()"
},
"time": "2026-05-11T20:49:54+00:00",
"time": "2026-07-17T23:02:45+00:00",
"type": "library",
"extra": {
"branch-alias": {
@ -433,7 +433,7 @@
],
"support": {
"issues": "https://github.com/nette/utils/issues",
"source": "https://github.com/nette/utils/tree/v4.1.4"
"source": "https://github.com/nette/utils/tree/v4.1.5"
},
"install-path": "../nette/utils"
},
@ -492,23 +492,23 @@
},
{
"name": "symfony/deprecation-contracts",
"version": "v3.7.0",
"version_normalized": "3.7.0.0",
"version": "v3.7.1",
"version_normalized": "3.7.1.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "50f59d1f3ca46d41ac911f97a78626b6756af35b"
"reference": "f3202fa1b5097b0af062dc978b32ecf63404e31d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/50f59d1f3ca46d41ac911f97a78626b6756af35b",
"reference": "50f59d1f3ca46d41ac911f97a78626b6756af35b",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/f3202fa1b5097b0af062dc978b32ecf63404e31d",
"reference": "f3202fa1b5097b0af062dc978b32ecf63404e31d",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"time": "2026-04-13T15:52:40+00:00",
"time": "2026-06-05T06:23:12+00:00",
"type": "library",
"extra": {
"thanks": {
@ -542,7 +542,7 @@
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.7.0"
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.7.1"
},
"funding": [
{

View file

@ -20,9 +20,9 @@
'dev_requirement' => false,
),
'league/commonmark' => array(
'pretty_version' => '2.8.2',
'version' => '2.8.2.0',
'reference' => '59fb075d2101740c337c7216e3f32b36c204218b',
'pretty_version' => '2.9.0',
'version' => '2.9.0.0',
'reference' => '5703d83ba3da3b2e356a5fedc848ed6d8ffb6529',
'type' => 'library',
'install_path' => __DIR__ . '/../league/commonmark',
'aliases' => array(),
@ -47,9 +47,9 @@
'dev_requirement' => false,
),
'nette/utils' => array(
'pretty_version' => 'v4.1.4',
'version' => '4.1.4.0',
'reference' => '7da6c396d7ebe142bc857c20479d5e70a5e1aac7',
'pretty_version' => 'v4.1.5',
'version' => '4.1.5.0',
'reference' => 'b043439dbdf954e6c28b5ea7e34b0100f83165e0',
'type' => 'library',
'install_path' => __DIR__ . '/../nette/utils',
'aliases' => array(),
@ -74,9 +74,9 @@
'dev_requirement' => false,
),
'symfony/deprecation-contracts' => array(
'pretty_version' => 'v3.7.0',
'version' => '3.7.0.0',
'reference' => '50f59d1f3ca46d41ac911f97a78626b6756af35b',
'pretty_version' => 'v3.7.1',
'version' => '3.7.1.0',
'reference' => 'f3202fa1b5097b0af062dc978b32ecf63404e31d',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/deprecation-contracts',
'aliases' => array(),

View file

@ -36,6 +36,8 @@ namespace PHPSTORM_META
'renderer/block_separator',
'renderer/inner_separator',
'renderer/soft_break',
'xml',
'xml/max_indentation_level',
'commonmark',
'commonmark/enable_em',
'commonmark/enable_strong',

View file

@ -6,6 +6,45 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
## [Unreleased][unreleased]
## [2.9.0] - 2026-08-03
This is a **security release** to address five denial of service vulnerabilities and one cross-site scripting (XSS) vulnerability.
### Added
- Added a new `NormalizeHeadingsExtension` to constrain headings to a configured level range (#989)
- Rewrites headings that skip levels so the resulting HTML is valid (#1115)
- `normalize_headings/rebase_to_min_level` - rebases each document so its headings begin at `min_level`
- Added a new `footnote/enable_inline_footnotes` config option to disable the inline `^[Footnote text]` syntax (#1112)
- Added `Cursor::getBytePosition()` for obtaining the cursor's current byte offset within the line
- Added a new `xml/max_indentation_level` config option to control how far `XmlRenderer` indents nested elements (default: `16`; set to `0` for unindented output)
### Changed
- The `FootnoteExtension` now uses only the first definition of a footnote label, removing any duplicate definitions instead of rendering them in place
- `NumberFootnotesListener` now stores footnote backrefs under a single `footnote/backrefs` key in the document data instead of one key per footnote destination
- Optimized `Cursor` to translate character positions to byte offsets in constant time instead of re-decoding the line with `mb_substr()`
- Optimized `Cursor::match()` to match against the line at the cursor's byte offset instead of copying the remaining line on every call
- Optimized `InlineParserEngine` and `UrlAutolinkParser` to work with byte offsets directly
### Fixed
- Fixed quadratic parsing performance on lines containing multibyte characters, which could be abused to cause a denial of service (GHSA-2q4p-g7hv-5rgv)
- Fixed the unsafe link filter failing to detect dangerous schemes obfuscated with embedded tabs, newlines, or leading control characters (such as `java<TAB>script:`), which allowed the `allow_unsafe_links` protection to be bypassed via `href` and `src` attributes (GHSA-29pj-957v-52mc)
- Fixed duplicate footnote definitions each claiming the full list of backrefs for their label, causing a quadratic number of backrefs to be generated, which could be abused to cause a denial of service (GHSA-jfm3-95jq-q3rf)
- Fixed footnote labels being treated as `.`/`/`-delimited key paths when storing backrefs, which allowed distinct labels such as `[^a.b]` and `[^a/b]` to share a single backref list (GHSA-jfm3-95jq-q3rf)
- Fixed a fatal error when one footnote label was a prefix of another, such as `[^a]` and `[^a.b]`
- Fixed the unique slug normalizer restarting its suffix search from `1` on every collision, causing headings or inline footnotes which normalize to the same slug to be de-duplicated in quadratic time, which could be abused to cause a denial of service (GHSA-mh25-x5hq-wrqp)
- Fixed the `AttributesExtension` scanning the remaining siblings of an inline attribute which can only apply to its parent block, causing long runs of adjacent inline attributes to be resolved in quadratic time, which could be abused to cause a denial of service (GHSA-g2gp-3wwq-f4ph)
- Fixed `XmlRenderer` indenting every element by its full nesting depth without any upper bound, causing deeply-nested documents to render as quadratically-sized XML, which could be abused to cause a denial of service (GHSA-mj63-m3rc-8ppr)
- Fixed `MarkDelimiterProcessor` not being declared as a `CacheableDelimiterProcessorInterface`, preventing the delimiter stack from caching the opener search for `==` runs (#1133)
## [2.8.3] - 2026-07-12
### Fixed
- Fixed tab-indented fenced code blocks inside list items losing the first character of each line and having their info string mangled (#981, #1130)
- Fixed the unsafe link filter incorrectly blocking safe URLs containing `vbscript:`, `file:`, or `data:` anywhere after the start (#1131)
## [2.8.2] - 2026-03-19
This is a **security release** to address an issue where the `allowed_domains` setting for the `Embed` extension can be bypassed, resulting in a possible SSRF and XSS vulnerabilities.
@ -732,7 +771,9 @@ No changes were introduced since the previous release.
- Alternative 1: Use `CommonMarkConverter` or `GithubFlavoredMarkdownConverter` if you don't need to customize the environment
- Alternative 2: Instantiate a new `Environment` and add the necessary extensions yourself
[unreleased]: https://github.com/thephpleague/commonmark/compare/2.8.2...HEAD
[unreleased]: https://github.com/thephpleague/commonmark/compare/2.9.0...HEAD
[2.9.0]: https://github.com/thephpleague/commonmark/compare/2.8.3...2.9.0
[2.8.3]: https://github.com/thephpleague/commonmark/compare/2.8.2...2.8.3
[2.8.2]: https://github.com/thephpleague/commonmark/compare/2.8.1...2.8.2
[2.8.1]: https://github.com/thephpleague/commonmark/compare/2.8.0...2.8.1
[2.8.0]: https://github.com/thephpleague/commonmark/compare/2.7.1...2.8.0

View file

@ -181,6 +181,7 @@ We'd also like to extend our sincere thanks the following sponsors who support o
- [Tidelift](https://tidelift.com/subscription/pkg/packagist-league-commonmark?utm_source=packagist-league-commonmark&utm_medium=referral&utm_campaign=readme) for offering support to both the maintainers and end-users through their [professional support](https://tidelift.com/subscription/pkg/packagist-league-commonmark?utm_source=packagist-league-commonmark&utm_medium=referral&utm_campaign=readme) program
- [Blackfire](https://www.blackfire.io/) for providing an Open-Source Profiler subscription
- [JetBrains](https://www.jetbrains.com/) for supporting this project with complimentary [PhpStorm](https://www.jetbrains.com/phpstorm/) licenses
- [Anthropic](https://www.anthropic.com/) for providing complimentary access to Claude Max through their [Open Source Program](https://claude.com/contact-sales/claude-for-oss)
Are you interested in sponsoring development of this project? See <https://www.colinodell.com/sponsor> for a list of ways to contribute.

View file

@ -39,8 +39,8 @@
"github/gfm": "0.29.0",
"michelf/php-markdown": "^1.4 || ^2.0",
"nyholm/psr7": "^1.5",
"phpstan/phpstan": "^1.8.2",
"phpunit/phpunit": "^9.5.21 || ^10.5.9 || ^11.0.0",
"phpstan/phpstan": "^2.0.0",
"phpunit/phpunit": "^9.5.21 || ^10.5.9 || ^11.0.0 || ^12.0.0 || ^13.0.0",
"scrutinizer/ocular": "^1.8.1",
"symfony/finder": "^5.3 | ^6.0 | ^7.0 || ^8.0",
"symfony/process": "^5.4 | ^6.0 | ^7.0 || ^8.0",
@ -116,7 +116,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "2.9-dev"
"dev-main": "2.10-dev"
}
},
"config": {

View file

@ -50,7 +50,7 @@ final class DelimiterStack
/** @psalm-suppress PropertyTypeCoercion */
$this->missingIndexCache = new \WeakMap(); // @phpstan-ignore-line
} else {
$this->missingIndexCache = new \SplObjectStorage(); // @phpstan-ignore-line
$this->missingIndexCache = new \SplObjectStorage();
}
}

View file

@ -438,6 +438,9 @@ final class Environment implements EnvironmentInterface, EnvironmentBuilderInter
'inner_separator' => Expect::string("\n"),
'soft_break' => Expect::string("\n"),
]),
'xml' => Expect::structure([
'max_indentation_level' => Expect::int()->min(0)->default(16),
]),
'slug_normalizer' => Expect::structure([
'instance' => Expect::type(TextNormalizerInterface::class)->default(new SlugNormalizer()),
'max_length' => Expect::int()->min(0)->default(255),

View file

@ -94,7 +94,16 @@ final class AttributesListener
}
if ($node instanceof AttributesInline && ($previous === null || ($previous instanceof AbstractInline && $node->isBlock()))) {
continue;
// Once this condition holds it holds for every remaining iteration, as walking
// further to the left can only ever yield another inline sibling or null. No
// sibling can therefore be chosen, so the target must be the parent; continuing
// to walk would only re-scan the remaining siblings for nothing.
if (! $node->parent() instanceof FencedCode) {
$target = $node->parent();
$direction = self::DIRECTION_SUFFIX;
}
break;
}
if ($previous !== null && ! self::isAttributesNode($previous)) {

View file

@ -23,7 +23,7 @@ final class UrlAutolinkParser implements InlineParserInterface
private const ALLOWED_AFTER = [null, ' ', "\t", "\n", "\x0b", "\x0c", "\x0d", '*', '_', '~', '('];
// RegEx adapted from https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/Validator/Constraints/UrlValidator.php
private const REGEX = '~^
private const REGEX = '~
(
# Must start with a supported scheme + auth, or "www"
(?:
@ -49,7 +49,7 @@ final class UrlAutolinkParser implements InlineParserInterface
(?:/ (?:[\pL\pN\-._\~!$&\'()*+,;=:@]|%%[0-9A-Fa-f]{2})* )* # a path
(?:\? (?:[\pL\pN\-._\~!$&\'\[\]()*+,;=:@/?]|%%[0-9A-Fa-f]{2})* )? # a query (optional)
(?:\# (?:[\pL\pN\-._\~!$&\'()*+,;=:@/?]|%%[0-9A-Fa-f]{2})* )? # a fragment (optional)
)~ixu';
)~ixuA';
/**
* @var string[]
@ -99,8 +99,11 @@ final class UrlAutolinkParser implements InlineParserInterface
return false;
}
// Check if we have a valid URL
if (! \preg_match($this->finalRegex, $cursor->getRemainder(), $matches)) {
// Check if we have a valid URL. The regex is anchored (the "A" modifier) and matched
// against the full line at the current byte offset rather than against a fresh copy of
// the remaining text. This avoids re-allocating and re-validating (the "u" modifier) the
// entire remainder on every prefix occurrence, which would otherwise be quadratic.
if (! \preg_match($this->finalRegex, $cursor->getLine(), $matches, 0, $cursor->getBytePosition())) {
return false;
}

View file

@ -51,10 +51,11 @@ final class FencedCodeParser extends AbstractBlockContinueParser
}
}
// Skip optional spaces of fence offset
// Optimization: don't attempt to match if we're at a non-space position
if ($cursor->getNextNonSpacePosition() > $cursor->getPosition()) {
$cursor->match('/^ {0,' . $this->block->getOffset() . '}/');
// Skip optional spaces of fence offset, counting columns instead of characters
// so that tabs are only partially consumed when needed
$fenceOffset = $this->block->getOffset();
while ($fenceOffset > 0 && $cursor->advanceBySpaceOrTab()) {
$fenceOffset--;
}
return BlockContinue::at($cursor);

View file

@ -30,14 +30,42 @@ final class GatherFootnotesListener implements ConfigurationAwareInterface
public function onDocumentParsed(DocumentParsedEvent $event): void
{
$document = $event->getDocument();
$footnotes = [];
$document = $event->getDocument();
$footnotes = [];
$definitions = [];
$discarded = [];
/** @var array<string, Reference[]> $backrefs */
$backrefs = $document->data->get('footnote/backrefs', []);
/*
* A label may be defined more than once. Only the first definition is used, matching how
* duplicate link reference definitions are resolved; the rest are discarded below.
*
* Keeping just one definition per label is also what bounds the work done here: every
* definition sharing a label claims that label's entire backref list, so N duplicate
* definitions of a label referenced M times would otherwise produce M * N backrefs - a
* denial of service vector, since both are attacker-controlled.
*
* Nodes are collected rather than detached here because detaching mid-iteration would
* truncate the walk.
*/
foreach ($document->iterator(NodeIterator::FLAG_BLOCKS_ONLY) as $node) {
if (! $node instanceof Footnote) {
continue;
}
$label = $node->getReference()->getLabel();
if (isset($definitions[$label])) {
$discarded[] = $node;
continue;
}
$definitions[$label] = $node;
}
foreach ($definitions as $node) {
// Look for existing reference with footnote label
$ref = $document->getReferenceMap()->get($node->getReference()->getLabel());
if ($ref !== null) {
@ -49,11 +77,15 @@ final class GatherFootnotesListener implements ConfigurationAwareInterface
}
$key = '#' . $this->config->get('footnote/footnote_id_prefix') . $node->getReference()->getDestination();
if ($document->data->has($key)) {
$this->createBackrefs($node, $document->data->get($key));
if (isset($backrefs[$key])) {
$this->createBackrefs($node, $backrefs[$key]);
}
}
foreach ($discarded as $duplicate) {
$duplicate->detach();
}
// Only add a footnote container if there are any
if (\count($footnotes) === 0) {
return;

View file

@ -26,6 +26,7 @@ final class NumberFootnotesListener
$nextCounter = 1;
$usedLabels = [];
$usedCounters = [];
$backrefs = [];
foreach ($document->iterator() as $node) {
if (! $node instanceof FootnoteRef) {
@ -59,10 +60,15 @@ final class NumberFootnotesListener
$document->getReferenceMap()->add($newReference);
/*
* Store created references in document for
* creating FootnoteBackrefs
* Store created references for creating FootnoteBackrefs.
*
* These are collected into a plain array keyed by the exact destination rather than
* written straight into $document->data: destinations are built from user-supplied
* labels, and Data treats both "." and "/" as key path delimiters. Using them as
* paths would let distinct labels collapse onto a shared entry, or nest one label's
* entry inside another's.
*/
$document->data->append($existingReference->getDestination(), $newReference);
$backrefs[$existingReference->getDestination()][] = $newReference;
$usedLabels[$label] = 1;
$usedCounters[$label] = $nextCounter;
@ -71,5 +77,7 @@ final class NumberFootnotesListener
$nextCounter++;
}
}
$document->data->set('footnote/backrefs', $backrefs);
}
}

View file

@ -44,6 +44,7 @@ final class FootnoteExtension implements ConfigurableExtensionInterface
'backref_symbol' => Expect::string('↩'),
'container_add_hr' => Expect::bool(true),
'container_class' => Expect::string('footnotes'),
'enable_inline_footnotes' => Expect::bool(true),
'ref_class' => Expect::string('footnote-ref'),
'ref_id_prefix' => Expect::string('fnref:'),
'footnote_class' => Expect::string('footnote'),
@ -53,8 +54,12 @@ final class FootnoteExtension implements ConfigurableExtensionInterface
public function register(EnvironmentBuilderInterface $environment): void
{
if ($environment->getConfiguration()->get('footnote/enable_inline_footnotes')) {
$environment->addInlineParser(new AnonymousFootnoteRefParser(), 35);
$environment->addEventListener(DocumentParsedEvent::class, [new AnonymousFootnotesListener(), 'onDocumentParsed'], 40);
}
$environment->addBlockStartParser(new FootnoteStartParser(), 51);
$environment->addInlineParser(new AnonymousFootnoteRefParser(), 35);
$environment->addInlineParser(new FootnoteRefParser(), 51);
$environment->addRenderer(FootnoteContainer::class, new FootnoteContainerRenderer());
@ -62,7 +67,6 @@ final class FootnoteExtension implements ConfigurableExtensionInterface
$environment->addRenderer(FootnoteRef::class, new FootnoteRefRenderer());
$environment->addRenderer(FootnoteBackref::class, new FootnoteBackrefRenderer());
$environment->addEventListener(DocumentParsedEvent::class, [new AnonymousFootnotesListener(), 'onDocumentParsed'], 40);
$environment->addEventListener(DocumentParsedEvent::class, [new FixOrphanedFootnotesAndRefsListener(), 'onDocumentParsed'], 30);
$environment->addEventListener(DocumentParsedEvent::class, [new NumberFootnotesListener(), 'onDocumentParsed'], 20);
$environment->addEventListener(DocumentParsedEvent::class, [new GatherFootnotesListener(), 'onDocumentParsed'], 10);

View file

@ -14,10 +14,10 @@ declare(strict_types=1);
namespace League\CommonMark\Extension\Highlight;
use League\CommonMark\Delimiter\DelimiterInterface;
use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface;
use League\CommonMark\Delimiter\Processor\CacheableDelimiterProcessorInterface;
use League\CommonMark\Node\Inline\AbstractStringContainer;
class MarkDelimiterProcessor implements DelimiterProcessorInterface
class MarkDelimiterProcessor implements CacheableDelimiterProcessorInterface
{
public function getOpeningCharacter(): string
{

View file

@ -41,14 +41,14 @@ final class CallbackGenerator implements MentionGeneratorInterface
return null;
}
if ($result instanceof AbstractInline && ! ($result instanceof Mention)) {
if ($result instanceof Mention) {
if ($result->hasUrl()) {
return $mention;
}
} elseif ($result instanceof AbstractInline) {
return $result;
}
if ($result instanceof Mention && $result->hasUrl()) {
return $mention;
}
throw new LogicException('CallbackGenerator callable must set the URL on the passed mention and return the mention, return a new AbstractInline based object or null if the mention is not a match');
}
}

Some files were not shown because too many files have changed in this diff Show more