fmt: fix backslash doubling in attribute string args (#9175)

pull/9218/head
Lukas Neubert 2021-03-07 08:44:58 +01:00 committed by GitHub
parent 053d6870d2
commit 6048d0e974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -1,3 +1,8 @@
struct AttrsWithEscpaedStringArgs {
dollar string [foo: '\$var']
double_bs string [bar: '\\baz']
}
[deprecated: 'use bar() instead']
[foo: bar]
[if debug; inline]

View File

@ -29,9 +29,7 @@ pub fn (attr Attr) str() string {
if attr.arg.len > 0 {
s += ': '
if attr.is_string_arg {
mut a := attr.arg.replace('\\', '\\\\')
// FIXME: other escapes e.g. \r\n
a = a.replace("'", "\\'")
a := attr.arg.replace("'", "\\'")
s += "'$a'"
} else {
s += attr.arg