Skip to content

Commit

Permalink
removed deprecated syntax on/off & \x** (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 18, 2021
1 parent f935573 commit 01b39ac
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 42 deletions.
9 changes: 2 additions & 7 deletions src/Neon/Parser/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ final class Exporter
private const PATTERN_BINARY = '#0b[0-1]++$#DA';

private const SIMPLE_TYPES = [
'true' => true, 'True' => true, 'TRUE' => true, 'yes' => true, 'Yes' => true, 'YES' => true, 'on' => true, 'On' => true, 'ON' => true,
'false' => false, 'False' => false, 'FALSE' => false, 'no' => false, 'No' => false, 'NO' => false, 'off' => false, 'Off' => false, 'OFF' => false,
'true' => true, 'True' => true, 'TRUE' => true, 'yes' => true, 'Yes' => true, 'YES' => true,
'false' => false, 'False' => false, 'FALSE' => false, 'no' => false, 'No' => false, 'NO' => false,
'null' => null, 'Null' => null, 'NULL' => null,
];

private const DEPRECATED_TYPES = ['on' => 1, 'On' => 1, 'ON' => 1, 'off' => 1, 'Off' => 1, 'OFF' => 1];


/** @var TokenStream */
private $tokens;
Expand Down Expand Up @@ -104,9 +102,6 @@ private function literalToVar(LiteralNode $node, bool $isKey = false): mixed
{
$value = $node->value;
if (!$isKey && array_key_exists($value, self::SIMPLE_TYPES)) {
if (isset(self::DEPRECATED_TYPES[$value])) {
trigger_error("Neon: keyword '$value' is deprecated, use true/yes or false/no.", E_USER_DEPRECATED);
}
return self::SIMPLE_TYPES[$value];

} elseif (is_numeric($value)) {
Expand Down
5 changes: 1 addition & 4 deletions src/Neon/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,13 @@ private function decodeString(string $s): string
}
if ($s[0] === '"') {
$res = preg_replace_callback(
'#\\\\(?:ud[89ab][0-9a-f]{2}\\\\ud[c-f][0-9a-f]{2}|u[0-9a-f]{4}|x[0-9a-f]{2}|.)#i',
'#\\\\(?:ud[89ab][0-9a-f]{2}\\\\ud[c-f][0-9a-f]{2}|u[0-9a-f]{4}|.)#i',
function (array $m): string {
$sq = $m[0];
if (isset(self::ESCAPE_SEQUENCES[$sq[1]])) {
return self::ESCAPE_SEQUENCES[$sq[1]];
} elseif ($sq[1] === 'u' && strlen($sq) >= 6) {
return $this->decodeUnicodeSequence($sq);
} elseif ($sq[1] === 'x' && strlen($sq) === 4) {
trigger_error("Neon: '$sq' is deprecated, use '\\uXXXX' instead.", E_USER_DEPRECATED);
return chr(hexdec(substr($sq, 2)));
} else {
$this->tokens->error("Invalid escaping sequence $sq", $this->tokens->getPos() - 1);
}
Expand Down
24 changes: 0 additions & 24 deletions tests/Neon/Decoder.deprecated.phpt

This file was deleted.

7 changes: 0 additions & 7 deletions tests/Neon/Decoder.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,6 @@ $dataSet = [

// deprecated NEON syntax
'deprecated syntax' => [
['on', true],
['On', true],
['ON', true],
['off', false],
['Off', false],
['OFF', false],
['"\\x42 hex escape"', "\x42 hex escape"],
],

// inputs with invalid syntax, but still valid UTF-8
Expand Down

0 comments on commit 01b39ac

Please sign in to comment.