mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-28 08:51:01 +02:00
parent
c3459153df
commit
80ce6ac112
10
ast/ast.go
10
ast/ast.go
@ -416,6 +416,16 @@ const (
|
||||
VerbatimStringSingle
|
||||
)
|
||||
|
||||
func (k LiteralStringKind) FullyEscaped() bool {
|
||||
switch k {
|
||||
case StringSingle, StringDouble:
|
||||
return true
|
||||
case StringBlock, VerbatimStringDouble, VerbatimStringSingle:
|
||||
return false
|
||||
}
|
||||
panic(fmt.Sprintf("Unknown string kind: %v", k))
|
||||
}
|
||||
|
||||
// LiteralString represents a JSON string
|
||||
type LiteralString struct {
|
||||
NodeBase
|
||||
|
@ -502,15 +502,15 @@ func desugar(astPtr *ast.Node, objLevel int) (err error) {
|
||||
// Nothing to do.
|
||||
|
||||
case *ast.LiteralString:
|
||||
if node.Kind != ast.VerbatimStringDouble && node.Kind != ast.VerbatimStringSingle {
|
||||
if node.Kind.FullyEscaped() {
|
||||
unescaped, err := stringUnescape(node.Loc(), node.Value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
node.Value = unescaped
|
||||
node.Kind = ast.StringDouble
|
||||
node.BlockIndent = ""
|
||||
}
|
||||
node.Kind = ast.StringDouble
|
||||
node.BlockIndent = ""
|
||||
case *ast.Object:
|
||||
// Hidden variable to allow $ binding.
|
||||
if objLevel == 0 {
|
||||
|
1
testdata/block_escaping.golden
vendored
Normal file
1
testdata/block_escaping.golden
vendored
Normal file
@ -0,0 +1 @@
|
||||
"\\n\n\\t\n"
|
4
testdata/block_escaping.jsonnet
vendored
Normal file
4
testdata/block_escaping.jsonnet
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
|||
|
||||
\n
|
||||
\t
|
||||
|||
|
Loading…
x
Reference in New Issue
Block a user