Skip to content

Commit 3d104cf

Browse files
committed
Merge pull request #1912 from tychosci/json-newline-after-outer-rparen
libstd: Skip trailing whitespaces after outer rparen
2 parents 4be9267 + ecf87c3 commit 3d104cf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libstd/json.rs

+10
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ impl parser for parser {
154154
fn parse() -> result::t<json, error> {
155155
alt self.parse_value() {
156156
ok(value) {
157+
// Skip trailing whitespaces.
158+
self.parse_whitespace();
157159
// Make sure there is no trailing characters.
158160
if self.eof() {
159161
ok(value)
@@ -627,6 +629,9 @@ mod tests {
627629
assert from_str("null") == ok(null);
628630
assert from_str("true") == ok(boolean(true));
629631
assert from_str("false") == ok(boolean(false));
632+
assert from_str(" null ") == ok(null);
633+
assert from_str(" true ") == ok(boolean(true));
634+
assert from_str(" false ") == ok(boolean(false));
630635
}
631636

632637
#[test]
@@ -654,6 +659,7 @@ mod tests {
654659
assert from_str("0.4e5") == ok(num(0.4e5f));
655660
assert from_str("0.4e+15") == ok(num(0.4e15f));
656661
assert from_str("0.4e-01") == ok(num(0.4e-01f));
662+
assert from_str(" 3 ") == ok(num(3f));
657663
}
658664

659665
#[test]
@@ -670,6 +676,7 @@ mod tests {
670676
assert from_str("\"\\n\"") == ok(string("\n"));
671677
assert from_str("\"\\r\"") == ok(string("\r"));
672678
assert from_str("\"\\t\"") == ok(string("\t"));
679+
assert from_str(" \"foo\" ") == ok(string("foo"));
673680
}
674681

675682
#[test]
@@ -691,6 +698,7 @@ mod tests {
691698
assert from_str("[ false ]") == ok(list([boolean(false)]));
692699
assert from_str("[null]") == ok(list([null]));
693700
assert from_str("[3, 1]") == ok(list([num(3f), num(1f)]));
701+
assert from_str("\n[3, 2]\n") == ok(list([num(3f), num(2f)]));
694702
assert from_str("[2, [4, 1]]") ==
695703
ok(list([num(2f), list([num(4f), num(1f)])]));
696704
}
@@ -727,6 +735,8 @@ mod tests {
727735

728736
assert eq(result::get(from_str("{ \"a\": null, \"b\" : true }")),
729737
mk_dict([("a", null), ("b", boolean(true))]));
738+
assert eq(result::get(from_str("\n{ \"a\": null, \"b\" : true }\n")),
739+
mk_dict([("a", null), ("b", boolean(true))]));
730740
assert eq(result::get(from_str("{\"a\" : 1.0 ,\"b\": [ true ]}")),
731741
mk_dict([
732742
("a", num(1.0)),

0 commit comments

Comments
 (0)