Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/HJSON/HJSONStringifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ private function isWhite($c)

private function quoteReplace($string)
{
mb_ereg_search_init($string, $this->needsEscape);
$r = mb_ereg_search();
$chars = mb_str_split($string);
$chars = array_map(function ($char) {
if (preg_match($this->needsEscape, $char)) {
Expand All @@ -111,7 +109,7 @@ private function quoteReplace($string)
if (gettype($c) === 'string') {
return $c;
} else {
return $char;
return substr(json_encode($char), 1, -1);
}
} else {
return $char;
Expand Down
8 changes: 7 additions & 1 deletion tests/HJSONParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private function runEach($name, $file, $isJson, $inputCr, $outputCr)
echo "Running test for $name, $file, ".(+$isJson).', '.(+$inputCr).', '.(+$outputCr)."\n";
$text = $this->load($file, $inputCr);
$shouldFail = substr($name, 0, 4) === "fail";
$unexpectedPass = false;

try {
$parser = new HJSONParser();
Expand Down Expand Up @@ -108,14 +109,19 @@ private function runEach($name, $file, $isJson, $inputCr, $outputCr)
$hjson2 = $this->load("{$name}_result.hjson", $outputCr);
$this->assertEquals($hjson1, $hjson2);
} else {
$this->markTestIncomplete('This test succeeded on data that should fail.');
$unexpectedPass = true;
}
} catch (HJSONException $e) {
if (!$shouldFail) {
echo "\n$e\n";
throw $e;
}
}

if ($unexpectedPass) {
echo "This test succeeded on data that should fail.\n";
throw new HJSONException();
}
}

public function testAll()
Expand Down
5 changes: 5 additions & 0 deletions tests/assets/charset2_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
uescape: "\u0000,\u0001,\uffff"
"um\u000blaut": äöüßÄÖÜ
hex: ģ䕧覫췯ꯍ
}
5 changes: 5 additions & 0 deletions tests/assets/charset2_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"uescape": "\u0000,\u0001,\uffff",
"um\u000blaut": "äöüßÄÖÜ",
"hex": "ģ䕧覫췯ꯍ"
}
5 changes: 5 additions & 0 deletions tests/assets/charset2_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
uescape: "\u0000,\u0001,\uffff"
"um\u000blaut": äöüßÄÖÜ
hex: "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A"
}
4 changes: 4 additions & 0 deletions tests/assets/failObj4_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a: 1
b: 2
# trailing bracket in bracketless root
}
5 changes: 4 additions & 1 deletion tests/assets/strings3_result.hjson
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
""
{
a: ""
b: "\u00ad\u0600\u0604\u070f\u17b4\u17b5\u200c\u200f\u2028\u202f\u2060\u206f\ufeff\ufff0\uffff"
}
5 changes: 4 additions & 1 deletion tests/assets/strings3_result.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
""
{
"a": "",
"b": "\u00ad\u0600\u0604\u070f\u17b4\u17b5\u200c\u200f\u2028\u202f\u2060\u206f\ufeff\ufff0\uffff"
}
7 changes: 6 additions & 1 deletion tests/assets/strings3_test.hjson
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
''''''
{
// Empty string
a: ""
// Unicode code points that require escape inside quotes.
b: "\u00ad\u0600\u0604\u070f\u17b4\u17b5\u200c\u200f\u2028\u202f\u2060\u206f\ufeff\ufff0\uffff"
}
1 change: 1 addition & 0 deletions tests/assets/strings4_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""
1 change: 1 addition & 0 deletions tests/assets/strings4_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""
1 change: 1 addition & 0 deletions tests/assets/strings4_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
''''''