From 14bab20b05bc20d16dec17401a9027c679412589 Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Sun, 9 Feb 2020 20:41:58 +0100 Subject: [PATCH] Backported ASCII detection for DataPath validation --- CHANGELOG.md | 18 ++++++++++++++++++ src/Components/DataPath.php | 10 +++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c9c51f89..ba898ad62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All Notable changes to `League\Uri\Components` will be documented in this file +## 2.2.1 - 2020-02-09 + +### Added + +- None + +### Fixed + +- back port improvement made to `DataUri` by [#154](https://github.com/thephpleague/uri/issues/154) thanks to [Nicolas Grekas](https://github.com/nicolas-grekas) + +### Deprecated + +- None + +### Remove + +- None + ## 2.2.0 - 2020-02-08 ### Added diff --git a/src/Components/DataPath.php b/src/Components/DataPath.php index cb3bd5110..b85bbe962 100644 --- a/src/Components/DataPath.php +++ b/src/Components/DataPath.php @@ -59,6 +59,14 @@ final class DataPath extends Component implements DataPathInterface private const REGEXP_DATAPATH = '/^\w+\/[-.\w]+(?:\+[-.\w]+)?;,$/'; + + /** + * All ASCII letters sorted by typical frequency of occurrence. + * + * @var string + */ + private const ASCII = "\x20\x65\x69\x61\x73\x6E\x74\x72\x6F\x6C\x75\x64\x5D\x5B\x63\x6D\x70\x27\x0A\x67\x7C\x68\x76\x2E\x66\x62\x2C\x3A\x3D\x2D\x71\x31\x30\x43\x32\x2A\x79\x78\x29\x28\x4C\x39\x41\x53\x2F\x50\x22\x45\x6A\x4D\x49\x6B\x33\x3E\x35\x54\x3C\x44\x34\x7D\x42\x7B\x38\x46\x77\x52\x36\x37\x55\x47\x4E\x3B\x4A\x7A\x56\x23\x48\x4F\x57\x5F\x26\x21\x4B\x3F\x58\x51\x25\x59\x5C\x09\x5A\x2B\x7E\x5E\x24\x40\x60\x7F\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; + /** * @var Path */ @@ -132,7 +140,7 @@ private function filterPath(?string $path): string $path = substr($path, 0, -1).'charset=us-ascii,'; } - if (1 === preg_match(self::REGEXP_NON_ASCII_PATTERN, $path) && false === strpos($path, ',')) { + if (strlen($path) !== strspn($path, self::ASCII) || false === strpos($path, ',')) { throw new SyntaxError(sprintf('The path `%s` is invalid according to RFC2937.', $path)); }