Przeglądaj źródła

#26 do not enforce pointer as optional

Tao Wen 8 lat temu
rodzic
commit
fc44cb2d91
2 zmienionych plików z 12 dodań i 2 usunięć
  1. 4 1
      feature_iter_object.go
  2. 8 1
      jsoniter_null_test.go

+ 4 - 1
feature_iter_object.go

@@ -108,8 +108,11 @@ func (iter *Iterator) readObjectStart() bool {
 		}
 		iter.unreadByte()
 		return true
+	} else if c == 'n' {
+		iter.skipFixedBytes(3)
+		return false
 	}
-	iter.reportError("readObjectStart", "expect { ")
+	iter.reportError("readObjectStart", "expect { or n")
 	return false
 }
 

+ 8 - 1
jsoniter_null_test.go

@@ -39,6 +39,7 @@ func Test_encode_null(t *testing.T) {
 }
 
 func Test_decode_null_object(t *testing.T) {
+	should := require.New(t)
 	iter := ParseString(`[null,"a"]`)
 	iter.ReadArray()
 	if iter.ReadObject() != "" {
@@ -48,6 +49,12 @@ func Test_decode_null_object(t *testing.T) {
 	if iter.ReadString() != "a" {
 		t.FailNow()
 	}
+	type TestObject struct {
+		Field string
+	}
+	objs := []TestObject{}
+	should.Nil(UnmarshalFromString("[null]", &objs))
+	should.Len(objs, 1)
 }
 
 func Test_decode_null_array(t *testing.T) {
@@ -66,7 +73,7 @@ func Test_decode_null_string(t *testing.T) {
 	should := require.New(t)
 	iter := ParseString(`[null,"a"]`)
 	should.True(iter.ReadArray())
-	should.True(iter.ReadNil())
+	should.Equal("", iter.ReadString())
 	should.True(iter.ReadArray())
 	should.Equal("a", iter.ReadString())
 }