Skip to content
Open
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
8 changes: 8 additions & 0 deletions legacy/candiedyaml/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ func resolveInterface(event yaml_event_t, useNumber bool) (string, interface{})
return "", val
}

// Honour an explicit !!str tag: the YAML spec requires that an explicit
// tag overrides implicit type resolution. Without this guard, values like
// `!!str off` or `!!str yes` are still coerced to booleans because the
// character-based dispatch below does not check the tag.
if string(event.tag) == yaml_STR_TAG {
return yaml_STR_TAG, val
}

if len(val) == 0 {
return yaml_NULL_TAG, nil
}
Expand Down
16 changes: 16 additions & 0 deletions legacy/candiedyaml/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,5 +661,21 @@ var _ = Describe("Resolver", func() {
Expect(tag).To(Equal(""))
})
})

Context("Explicit !!str tag preserves string (no bool coercion)", func() {
strTagBoolTokens := []string{"on", "ON", "off", "OFF", "yes", "YES", "no", "NO", "true", "TRUE", "false", "FALSE", "y", "Y", "n", "N"}

It("returns the raw string for each YAML 1.1 bool token tagged !!str", func() {
for _, tok := range strTagBoolTokens {
event.value = []byte(tok)
event.tag = []byte(yaml_STR_TAG)
event.implicit = false

tag, result := resolveInterface(event, false)
Expect(tag).To(Equal(yaml_STR_TAG), "token %q: expected tag !!str", tok)
Expect(result).To(Equal(tok), "token %q: expected string, not bool", tok)
}
})
})
})
})