Make output of unquoted Lua table keys optional

Generally safer and simpler to not do it.
This commit is contained in:
Kim Alvefur 2023-07-31 08:04:42 +02:00
parent c8919f20da
commit cabb73b12c

View File

@ -10,6 +10,7 @@ import (
type luaEncoder struct { type luaEncoder struct {
docPrefix string docPrefix string
docSuffix string docSuffix string
unquoted bool
escape *strings.Replacer escape *strings.Replacer
} }
@ -56,7 +57,7 @@ func NewLuaEncoder() Encoder {
"\\", "\\\\", "\\", "\\\\",
"\177", "\\127", "\177", "\\127",
) )
return &luaEncoder{"return ", ";\n", escape} return &luaEncoder{"return ", ";\n", false, escape}
} }
func (le *luaEncoder) PrintDocumentSeparator(writer io.Writer) error { func (le *luaEncoder) PrintDocumentSeparator(writer io.Writer) error {
@ -131,7 +132,7 @@ func (le *luaEncoder) encodeMap(writer io.Writer, node *yaml.Node) error {
if err != nil { if err != nil {
return err return err
} }
} else if child.Tag == "!!str" && !needsQuoting(child.Value) { } else if le.unquoted && child.Tag == "!!str" && !needsQuoting(child.Value) {
err = writeString(writer, child.Value+"=") err = writeString(writer, child.Value+"=")
if err != nil { if err != nil {
return err return err