Skip to content
Closed
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,26 @@ c:
source: "42: 100",
value: map[int]any{42: 100},
},
{
source: "{hello:world: [a,b,c]}",
value: map[string]any{"hello:world": []any{"a", "b", "c"}},
},
{
source: "{a:b:c: value}",
value: map[string]any{"a:b:c": "value"},
},
{
source: "{host:port: 8080, name: test}",
value: map[string]any{"host:port": uint64(8080), "name": "test"},
},
{
source: "{a:b: {c: d}}",
value: map[string]any{"a:b": map[string]any{"c": "d"}},
},
{
source: "{a:b: [1,2]}",
value: map[string]any{"a:b": []any{uint64(1), uint64(2)}},
},
}
for _, test := range tests {
t.Run(test.source, func(t *testing.T) {
Expand Down
13 changes: 11 additions & 2 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,17 @@ func (s *Scanner) scanMapDelim(ctx *Context) (bool, error) {
if s.startedFlowMapNum <= 0 && nc != ' ' && nc != '\t' && !s.isNewLineChar(nc) && !ctx.isNextEOS() {
return false, nil
}
if s.startedFlowMapNum > 0 && nc == '/' {
// like http://
if s.startedFlowMapNum > 0 && len(ctx.buf) > 0 &&
nc != ' ' && nc != '\t' && !s.isNewLineChar(nc) &&
nc != ',' && nc != '}' && nc != ']' && nc != '[' && nc != '{' &&
nc != '"' && nc != '\'' && !ctx.isNextEOS() {
// In flow mapping context, when scanning a plain scalar key (buf is non-empty),
// ':' is only a mapping value indicator when followed by whitespace,
// a flow indicator (',', '}', ']'), a flow collection start ('[', '{'),
// a quote ('"', '\''), or end of input.
// This allows unquoted keys like 'hello:world' and URLs like 'http://example.com'.
// When buf is empty the key was already tokenized (e.g. as a quoted string),
// so ':' is unambiguously a mapping value indicator.
return false, nil
}
if s.startedFlowMapNum > 0 {
Expand Down
Loading