Skip to content

Commit

Permalink
Backported ASCII detection for DataPath validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Feb 9, 2020
1 parent cd1716c commit 14bab20
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/Components/DataPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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));
}

Expand Down

0 comments on commit 14bab20

Please sign in to comment.