mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
strconv: fix v_sprintf with '%%' (#17708)
This commit is contained in:
parent
3793bf1c99
commit
9275161d0f
@ -113,3 +113,9 @@ fn test_sprintf_does_not_double_free_on_g() {
|
||||
x := 3.141516
|
||||
assert strconv.v_sprintf('aaa %G', x) == 'aaa 3.141516'
|
||||
}
|
||||
|
||||
fn test_sprintf_with_escape() {
|
||||
n := 69
|
||||
s := strconv.v_sprintf('%d is 100%% awesome', n)
|
||||
assert s == '69 is 100% awesome'
|
||||
}
|
||||
|
@ -75,6 +75,12 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if ch == `%` && status == .field_char {
|
||||
status = .norm_char
|
||||
res.write_u8(ch)
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if ch == `%` && status == .norm_char {
|
||||
status = .field_char
|
||||
i++
|
||||
|
Loading…
Reference in New Issue
Block a user