diff --git a/cmd/tools/performance_compare.v b/cmd/tools/performance_compare.v index 3cb368493f..6723231524 100644 --- a/cmd/tools/performance_compare.v +++ b/cmd/tools/performance_compare.v @@ -152,7 +152,7 @@ fn (c Context) compare_v_performance(label string, commands []string) string { println(cmd) } for cmd in commands { - hyperfine_commands_arguments << " \'cd ${c.b:-34s} ; ./$cmd \' ".replace_each([ + hyperfine_commands_arguments << ' \'cd ${c.b:-34s} ; ./$cmd \' '.replace_each([ '@COMPILER@', source_location_b, '@DEBUG@', @@ -160,7 +160,7 @@ fn (c Context) compare_v_performance(label string, commands []string) string { ]) } for cmd in commands { - hyperfine_commands_arguments << " \'cd ${c.a:-34s} ; ./$cmd \' ".replace_each([ + hyperfine_commands_arguments << ' \'cd ${c.a:-34s} ; ./$cmd \' '.replace_each([ '@COMPILER@', source_location_a, '@DEBUG@', diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 147d0e52bf..7492c2465c 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -792,8 +792,8 @@ fn test_raw_with_quotes() { fn test_escape() { a := 10 - println('\"$a') - assert '\"$a' == '"10' + println("\"$a") + assert "\"$a" == '"10' } fn test_atoi() { diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 76f77a964e..b3237538cc 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -171,7 +171,7 @@ pub fn (mut c Checker) check_matching_function_symbols(got_type_sym &ast.TypeSym if exp_arg_is_ptr != got_arg_is_ptr { exp_arg_pointedness := if exp_arg_is_ptr { 'a pointer' } else { 'NOT a pointer' } got_arg_pointedness := if got_arg_is_ptr { 'a pointer' } else { 'NOT a pointer' } - c.add_error_detail("`$exp_fn.name`\'s expected fn argument: `$exp_arg.name` is $exp_arg_pointedness, but the passed fn argument: `$got_arg.name` is $got_arg_pointedness") + c.add_error_detail('`$exp_fn.name`\'s expected fn argument: `$exp_arg.name` is $exp_arg_pointedness, but the passed fn argument: `$got_arg.name` is $got_arg_pointedness') return false } if !c.check_basic(got_arg.typ, exp_arg.typ) { diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index da9f709afc..04cc33b720 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -2343,12 +2343,19 @@ pub fn (mut f Fmt) string_inter_literal(node ast.StringInterLiteral) { // TODO: this code is very similar to ast.Expr.str() mut quote := "'" for val in node.vals { - if val.contains("'") { + if val.contains('\\"') { quote = '"' + break + } + if val.contains("\\'") { + quote = "'" + break } if val.contains('"') { quote = "'" - break + } + if val.contains("'") { + quote = '"' } } f.write(quote) diff --git a/vlib/v/fmt/tests/string_interpolation_complex_keep.vv b/vlib/v/fmt/tests/string_interpolation_complex_keep.vv new file mode 100644 index 0000000000..470ee54141 --- /dev/null +++ b/vlib/v/fmt/tests/string_interpolation_complex_keep.vv @@ -0,0 +1,9 @@ +struct Container { + id string +} + +container := Container{} +docker_pubkey := '1234657890' + +cmd := "docker exec $container.id sh -c 'echo \"$docker_pubkey\" >> ~/.ssh/authorized_keys'" +println(cmd) diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index 7f210db77c..bad8ee6130 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -938,7 +938,7 @@ fn (mut g JsGen) gen_for_in_stmt(it ast.ForInStmt) { if it.kind == .string { g.write('Array.from(') g.expr(it.cond) - g.write(".str.split(\'\').entries(), ([$it.key_var, $val]) => [$it.key_var, ") + g.write('.str.split(\'\').entries(), ([$it.key_var, $val]) => [$it.key_var, ') if g.ns.name == 'builtin' { g.write('new ') } diff --git a/vlib/v/tests/interface_struct_test.v b/vlib/v/tests/interface_struct_test.v index b1478d1fba..879b873eba 100644 --- a/vlib/v/tests/interface_struct_test.v +++ b/vlib/v/tests/interface_struct_test.v @@ -8,7 +8,7 @@ struct Boss { } fn (b Boss) say_hello() string { - return "Hello, My name is $b.name and I\'m the bawz" + return 'Hello, My name is $b.name and I\'m the bawz' } fn (b Boss) speak(msg string) { diff --git a/vlib/vweb/request_test.v b/vlib/vweb/request_test.v index ad6d960a72..b935a2e2e9 100644 --- a/vlib/vweb/request_test.v +++ b/vlib/vweb/request_test.v @@ -100,7 +100,7 @@ fn test_parse_multipart_form() { file := 'bar.v' ct := 'application/octet-stream' contents := ['baz', 'buzz'] - data := '--------------------------$boundary + data := "--------------------------$boundary Content-Disposition: form-data; name=\"${names[0]}\"; filename=\"$file\" Content-Type: $ct @@ -110,7 +110,7 @@ Content-Disposition: form-data; name=\"${names[1]}\" ${contents[1]} --------------------------$boundary-- -' +" form, files := parse_multipart_form(data, boundary) assert files == map{ names[0]: [FileData{ diff --git a/vlib/vweb/tests/vweb_test.v b/vlib/vweb/tests/vweb_test.v index 8951c33adc..83e5e7583f 100644 --- a/vlib/vweb/tests/vweb_test.v +++ b/vlib/vweb/tests/vweb_test.v @@ -213,12 +213,12 @@ fn test_http_client_multipart_form_data() ? { name := 'foo' ct := 'multipart/form-data; boundary=------------------------$boundary' contents := 'baz buzz' - data := '--------------------------$boundary + data := "--------------------------$boundary Content-Disposition: form-data; name=\"$name\" $contents --------------------------$boundary-- -' +" mut x := http.fetch('http://127.0.0.1:$sport/form_echo', method: .post header: http.new_header(