diff --git a/lib/go/camli/schema/schema.go b/lib/go/camli/schema/schema.go index 35d7ccc5f..f5717cd47 100644 --- a/lib/go/camli/schema/schema.go +++ b/lib/go/camli/schema/schema.go @@ -107,11 +107,10 @@ func stringFromMixedArray(parts []interface{}) string { buf.WriteString(s) continue } - if b, ok := part.(byte); ok { - buf.WriteByte(b) + if num, ok := part.(float64); ok { + buf.WriteByte(byte(num)) continue } - // TODO: finish / test (see what types actually come from JSON unmarshalling) } return buf.String() } diff --git a/lib/go/camli/schema/schema_test.go b/lib/go/camli/schema/schema_test.go index 4623064df..041e82769 100644 --- a/lib/go/camli/schema/schema_test.go +++ b/lib/go/camli/schema/schema_test.go @@ -18,6 +18,7 @@ package schema import ( . "camli/test/asserts" + "json" "os" "strings" "testing" @@ -103,4 +104,27 @@ func TestSymlink(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } t.Logf("Got json for symlink file: [%s]\n", json) +} + +type mixPartsTest struct { + json, expected string +} + +func TestStringFromMixedArray(t *testing.T) { + tests := []mixPartsTest{ + {`["brad"]`, "brad"}, + {`["brad", 32, 70]`, "brad F"}, + {`["brad", "fitz"]`, "bradfitz"}, + {`["../foo/Am", 233, "lie.jpg"]`, "../foo/Am\xe9lie.jpg"}, + } + for idx, test := range tests { + var v []interface{} + if err := json.Unmarshal([]byte(test.json), &v); err != nil { + t.Fatalf("invalid JSON in test %d", idx) + } + got := stringFromMixedArray(v) + if got != test.expected { + t.Errorf("test %d got %q; expected %q", idx, got, test.expected) + } + } } \ No newline at end of file