about summary refs log tree commit diff
path: root/src/libserialize
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-09-17 08:49:04 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-09-17 08:49:04 -0700
commite8a3ac5cb08cc7dc210c6b86abcb4669588e7111 (patch)
treedea164dd4cd0d92070c92840b9d794207d03364f /src/libserialize
parent27af6910171b407a314d5d768667233693c42ee3 (diff)
parentfb299bd85f7d836e3f0ae7b39ae53dfdc3eebed2 (diff)
downloadrust-e8a3ac5cb08cc7dc210c6b86abcb4669588e7111.tar.gz
rust-e8a3ac5cb08cc7dc210c6b86abcb4669588e7111.zip
rollup merge of #17276 : treeman/json-comma
Diffstat (limited to 'src/libserialize')
-rw-r--r--src/libserialize/json.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs
index e9c3a2afb03..833c5cd0f98 100644
--- a/src/libserialize/json.rs
+++ b/src/libserialize/json.rs
@@ -234,6 +234,7 @@ pub enum ErrorCode {
     KeyMustBeAString,
     ExpectedColon,
     TrailingCharacters,
+    TrailingComma,
     InvalidEscape,
     InvalidUnicodeCodePoint,
     LoneLeadingSurrogateInHexEscape,
@@ -274,6 +275,7 @@ pub fn error_str(error: ErrorCode) -> &'static str {
         KeyMustBeAString => "key must be a string",
         ExpectedColon => "expected `:`",
         TrailingCharacters => "trailing characters",
+        TrailingComma => "trailing comma",
         InvalidEscape => "invalid escape",
         UnrecognizedHex => "invalid \\u escape (unrecognized hex)",
         NotFourDigit => "invalid \\u escape (not four digits)",
@@ -1681,7 +1683,11 @@ impl<T: Iterator<char>> Parser<T> {
     fn parse_object(&mut self, first: bool) -> JsonEvent {
         if self.ch_is('}') {
             if !first {
-                self.stack.pop();
+                if self.stack.is_empty() {
+                    return self.error_event(TrailingComma);
+                } else {
+                    self.stack.pop();
+                }
             }
             if self.stack.is_empty() {
                 self.state = ParseBeforeFinish;
@@ -2377,7 +2383,7 @@ mod tests {
                 F64Value, StringValue, NullValue, SyntaxError, Key, Index, Stack,
                 InvalidSyntax, InvalidNumber, EOFWhileParsingObject, EOFWhileParsingList,
                 EOFWhileParsingValue, EOFWhileParsingString, KeyMustBeAString, ExpectedColon,
-                TrailingCharacters};
+                TrailingCharacters, TrailingComma};
     use std::{i64, u64, f32, f64, io};
     use std::collections::TreeMap;
 
@@ -3379,6 +3385,7 @@ mod tests {
             }
         }
     }
+
     #[test]
     #[ignore(cfg(target_word_size = "32"))] // FIXME(#14064)
     fn test_read_object_streaming() {
@@ -3393,6 +3400,7 @@ mod tests {
         assert_eq!(last_event("{\"a\":1"),   Error(SyntaxError(EOFWhileParsingObject, 1, 7)));
         assert_eq!(last_event("{\"a\":1 1"), Error(SyntaxError(InvalidSyntax,         1, 8)));
         assert_eq!(last_event("{\"a\":1,"),  Error(SyntaxError(EOFWhileParsingObject, 1, 8)));
+        assert_eq!(last_event("{\"a\":1,}"), Error(SyntaxError(TrailingComma, 1, 8)));
 
         assert_stream_equal(
             "{}",