diff options
author | alandonovan <adonovan@google.com> | 2020-03-26 10:23:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-26 10:23:16 -0400 |
commit | 16e44b11d94568b6de240a245c9f85c415e69bbc (patch) | |
tree | c91e9af517b59d87d697303f03c001bbd5fb900b /starlarkstruct | |
parent | 8dd3e2ee1dd5d034baada4c7b4fcf231294a1013 (diff) | |
download | starlark-go-16e44b11d94568b6de240a245c9f85c415e69bbc.tar.gz |
syntax: strict string escapes (#265)
This change causes Starlark, like Go, to reject backslashes that
are not part of an escape sequence. Previously they were treated
literally, so \ ( would encode a two-character string.
Many programs rely on this, especially for regular expressions and
shell commands, and will be broken by this change, but the fix is simple:
double each errant backslash.
Python does not yet enforce this behavior, but since 3.6
has emitted a deprecation warning for it.
Also, document string escapes.
Related issues:
- Google issue b/34519173: "bazel: Forbid undefined escape sequences in strings"
- bazelbuild/starlark#38: Starlark spec: String escapes
- bazelbuild/buildtools#688: Bazel: Fix string escapes
- bazelbuild/bazel#8380: Bazel incompatible_restrict_string_escapes: Restrict string escapes
Diffstat (limited to 'starlarkstruct')
-rw-r--r-- | starlarkstruct/testdata/struct.star | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/starlarkstruct/testdata/struct.star b/starlarkstruct/testdata/struct.star index 841ab41..e54fe04 100644 --- a/starlarkstruct/testdata/struct.star +++ b/starlarkstruct/testdata/struct.star @@ -58,6 +58,6 @@ assert.eq(getattr(alice, "city"), "NYC") assert.eq(bob + bob, bob) assert.eq(bob + alice, person(age = 50, city = "NYC", name = "alice")) assert.eq(alice + bob, person(age = 50, city = "NYC", name = "bob")) # not commutative! a misfeature -assert.fails(lambda : alice + 1, "struct \+ int") +assert.fails(lambda : alice + 1, "struct \\+ int") assert.eq(http + http, http) -assert.fails(lambda : http + bob, "different constructors: hostport \+ person") +assert.fails(lambda : http + bob, "different constructors: hostport \\+ person") |