diff --git a/src/github.com/couchbase/sync_gateway/db/database_test.go b/src/github.com/couchbase/sync_gateway/db/database_test.go index 0b2a342bbb..d2be9882e6 100644 --- a/src/github.com/couchbase/sync_gateway/db/database_test.go +++ b/src/github.com/couchbase/sync_gateway/db/database_test.go @@ -722,6 +722,20 @@ func TestPutWithUserSpecialProperty(t *testing.T) { assert.True(t, err.Error() == "400 user defined top level properties beginning with '_' are not allowed in document body") } +// Unit test for issue #976 +func TestWithNullPropertyKey(t *testing.T) { + db := setupTestDB(t) + defer tearDownTestDB(t, db) + + // Test creating a document with null property key + customDocId := "customIdValue" + log.Printf("Create document with empty property key") + body := Body{"_id": customDocId, "": "value1"} + docid, rev1id, _ := db.Post(body) + assert.True(t, rev1id != "") + assert.True(t, docid != "") +} + // Unit test for issue #507 func TestPostWithUserSpecialProperty(t *testing.T) { db := setupTestDB(t) diff --git a/src/github.com/couchbase/sync_gateway/db/revision.go b/src/github.com/couchbase/sync_gateway/db/revision.go index b7e2d84c6e..81f52f21da 100644 --- a/src/github.com/couchbase/sync_gateway/db/revision.go +++ b/src/github.com/couchbase/sync_gateway/db/revision.go @@ -153,7 +153,7 @@ func stripSpecialProperties(body Body) Body { func containsUserSpecialProperties(body Body) bool { for key, _ := range body { - if key[0] == '_' && key != "_id" && key != "_rev" && key != "_deleted" && key != "_attachments" && key != "_revisions" { + if key != "" && key[0] == '_' && key != "_id" && key != "_rev" && key != "_deleted" && key != "_attachments" && key != "_revisions" { return true } }