mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-28 17:01:02 +02:00
parent
c3459153df
commit
80ce6ac112
10
ast/ast.go
10
ast/ast.go
@ -416,6 +416,16 @@ const (
|
|||||||
VerbatimStringSingle
|
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
|
// LiteralString represents a JSON string
|
||||||
type LiteralString struct {
|
type LiteralString struct {
|
||||||
NodeBase
|
NodeBase
|
||||||
|
@ -502,15 +502,15 @@ func desugar(astPtr *ast.Node, objLevel int) (err error) {
|
|||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
|
|
||||||
case *ast.LiteralString:
|
case *ast.LiteralString:
|
||||||
if node.Kind != ast.VerbatimStringDouble && node.Kind != ast.VerbatimStringSingle {
|
if node.Kind.FullyEscaped() {
|
||||||
unescaped, err := stringUnescape(node.Loc(), node.Value)
|
unescaped, err := stringUnescape(node.Loc(), node.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
node.Value = unescaped
|
node.Value = unescaped
|
||||||
node.Kind = ast.StringDouble
|
|
||||||
node.BlockIndent = ""
|
|
||||||
}
|
}
|
||||||
|
node.Kind = ast.StringDouble
|
||||||
|
node.BlockIndent = ""
|
||||||
case *ast.Object:
|
case *ast.Object:
|
||||||
// Hidden variable to allow $ binding.
|
// Hidden variable to allow $ binding.
|
||||||
if objLevel == 0 {
|
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