From af60f9ead4639dd77bae63c171d7db213b1b0d37 Mon Sep 17 00:00:00 2001 From: Henrixounez Date: Wed, 11 Sep 2019 14:21:20 +0200 Subject: [PATCH] compiler: escapes quote on literals --- compiler/scanner.v | 3 ++- vlib/builtin/string_test.v | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/scanner.v b/compiler/scanner.v index a22c77cb14..bcacd9e96f 100644 --- a/compiler/scanner.v +++ b/compiler/scanner.v @@ -752,7 +752,8 @@ fn (s mut Scanner) ident_char() string { s.error('invalid character literal (more than one character: $len)') } } - return c + // Escapes a `'` character + return if c == '\'' { '\\' + c } else { c } } fn (s mut Scanner) peek() Token { diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 505a45b2aa..eff83f40cb 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -418,3 +418,8 @@ fn test_for_loop_two() { assert c == s[i] } } + +fn test_quote() { + a := `'` + assert a.str() == '\'' +}