mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
ast: fix double-fix for refs["with-a"].dash as package
Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
This commit is contained in:
committed by
Stephan Renatus
parent
e426fd7c76
commit
c90bfeb91a
@@ -68,15 +68,6 @@ func (pkg *Package) AppendText(buf []byte) ([]byte, error) {
|
||||
|
||||
path := pkg.Path[1:] // omit "data"
|
||||
|
||||
if s, ok := path[0].Value.(String); ok {
|
||||
buf = append(buf, s...) // first term should never be quoted
|
||||
if len(path) == 1 {
|
||||
return buf, nil
|
||||
}
|
||||
buf = append(buf, '.')
|
||||
path = path[1:]
|
||||
}
|
||||
|
||||
return path.AppendText(buf)
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,18 @@ r = true`,
|
||||
},
|
||||
want: `package example.foo`,
|
||||
},
|
||||
{
|
||||
name: "package with special chars",
|
||||
node: &ast.Package{
|
||||
Path: ast.Ref{
|
||||
ast.DefaultRootDocument,
|
||||
ast.StringTerm("pkg"),
|
||||
ast.StringTerm("with-a"),
|
||||
ast.StringTerm("dash"),
|
||||
},
|
||||
},
|
||||
want: `package pkg["with-a"].dash`,
|
||||
},
|
||||
{
|
||||
name: "import",
|
||||
node: &ast.Import{
|
||||
|
||||
Reference in New Issue
Block a user