Skip to content
Merged
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
10 changes: 10 additions & 0 deletions src/libstd/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ impl parser for parser {
fn parse() -> result::t<json, error> {
alt self.parse_value() {
ok(value) {
// Skip trailing whitespaces.
self.parse_whitespace();
// Make sure there is no trailing characters.
if self.eof() {
ok(value)
Expand Down Expand Up @@ -627,6 +629,9 @@ mod tests {
assert from_str("null") == ok(null);
assert from_str("true") == ok(boolean(true));
assert from_str("false") == ok(boolean(false));
assert from_str(" null ") == ok(null);
assert from_str(" true ") == ok(boolean(true));
assert from_str(" false ") == ok(boolean(false));
}

#[test]
Expand Down Expand Up @@ -654,6 +659,7 @@ mod tests {
assert from_str("0.4e5") == ok(num(0.4e5f));
assert from_str("0.4e+15") == ok(num(0.4e15f));
assert from_str("0.4e-01") == ok(num(0.4e-01f));
assert from_str(" 3 ") == ok(num(3f));
}

#[test]
Expand All @@ -670,6 +676,7 @@ mod tests {
assert from_str("\"\\n\"") == ok(string("\n"));
assert from_str("\"\\r\"") == ok(string("\r"));
assert from_str("\"\\t\"") == ok(string("\t"));
assert from_str(" \"foo\" ") == ok(string("foo"));
}

#[test]
Expand All @@ -691,6 +698,7 @@ mod tests {
assert from_str("[ false ]") == ok(list([boolean(false)]));
assert from_str("[null]") == ok(list([null]));
assert from_str("[3, 1]") == ok(list([num(3f), num(1f)]));
assert from_str("\n[3, 2]\n") == ok(list([num(3f), num(2f)]));
assert from_str("[2, [4, 1]]") ==
ok(list([num(2f), list([num(4f), num(1f)])]));
}
Expand Down Expand Up @@ -727,6 +735,8 @@ mod tests {

assert eq(result::get(from_str("{ \"a\": null, \"b\" : true }")),
mk_dict([("a", null), ("b", boolean(true))]));
assert eq(result::get(from_str("\n{ \"a\": null, \"b\" : true }\n")),
mk_dict([("a", null), ("b", boolean(true))]));
assert eq(result::get(from_str("{\"a\" : 1.0 ,\"b\": [ true ]}")),
mk_dict([
("a", num(1.0)),
Expand Down