1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
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'] [deprecated: 'use bar() instead']
[foo: bar] [foo: bar]
[if debug; inline] [if debug; inline]

View File

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