Skip to content

Commit 25903ec

Browse files
committed
fix err on bad \u char
1 parent 0ca9211 commit 25903ec

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

src/HJSON/HJSONParser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ private function string()
105105
for ($i = 0; $i < 4; $i++) {
106106
$uffff .= $this->next();
107107
}
108-
$uffff = json_decode('"\u' . $uffff . '"');
109-
$string .= $uffff;
108+
if (!ctype_xdigit($uffff))
109+
$this->error("Bad \\u char");
110+
$string .= mb_convert_encoding(pack('H*', $uffff), 'UTF-8', 'UTF-16BE');
110111
}
111112
else if (@$this->escapee[$this->ch]) {
112113
$string .= $this->escapee[$this->ch];

tests/assets/failKey4_test.hjson

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
# invalid name
3+
: 0
4+
}

tests/assets/failMLStr1_test.hjson

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
# invalid multiline string
3+
ml: '''

tests/assets/failStr7_test.hjson

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
# invalid \u char
3+
char: "\uxxxx"
4+
}

tests/assets/testlist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ fail8_test.json
3131
failKey1_test.hjson
3232
failKey2_test.hjson
3333
failKey3_test.hjson
34+
failKey4_test.hjson
35+
failMLStr1_test.hjson
3436
failObj1_test.hjson
3537
failObj2_test.hjson
3638
failObj3_test.hjson
@@ -40,6 +42,7 @@ failStr3_test.hjson
4042
failStr4_test.hjson
4143
failStr5_test.hjson
4244
failStr6_test.hjson
45+
failStr7_test.hjson
4346
kan_test.hjson
4447
keys_test.hjson
4548
oa_test.hjson

0 commit comments

Comments
 (0)