From e6ce3bc58b38f7edd41733ed1b708851099076cc Mon Sep 17 00:00:00 2001 From: BooksBaum <15612932+Booksbaum@users.noreply.github.com> Date: Mon, 18 Sep 2023 14:55:22 +0200 Subject: [PATCH] Fix: Produces unescaped single quotation mark for char Note: Double Quotation marks remain unescaped --- .../CodeFixes/AdjustConstant.fs | 4 ++- .../CodeFixTests/AdjustConstantTests.fs | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/FsAutoComplete/CodeFixes/AdjustConstant.fs b/src/FsAutoComplete/CodeFixes/AdjustConstant.fs index 8df9db070..0a39eba3e 100644 --- a/src/FsAutoComplete/CodeFixes/AdjustConstant.fs +++ b/src/FsAutoComplete/CodeFixes/AdjustConstant.fs @@ -610,8 +610,10 @@ module private Format = | '\t' -> Some "\\t" | '\v' -> Some "\\v" | '\\' -> Some "\\" + // Note: double quotation marks can be escaped -- but don't have to be. + // We're emitting unescaped quotations: `'"'` and not `'\"'` | '\"' -> Some "\"" - | '\'' -> Some "\'" + | '\'' -> Some "\\\'" | _ when Char.IsControl c -> None | c -> Some (string c) diff --git a/test/FsAutoComplete.Tests.Lsp/CodeFixTests/AdjustConstantTests.fs b/test/FsAutoComplete.Tests.Lsp/CodeFixTests/AdjustConstantTests.fs index c730a6d16..a8100bb4d 100644 --- a/test/FsAutoComplete.Tests.Lsp/CodeFixTests/AdjustConstantTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/CodeFixTests/AdjustConstantTests.fs @@ -962,6 +962,32 @@ module private ConvertCharToOtherForm = "\\u2248" "\\U00002248" + checkAll server "can convert single quotation mark" + "let c = '{char}'" + "\\\'" + "\\039" + "\\x27" + "\\u0027" + "\\U00000027" + + checkAll server "can convert unescaped double quotation mark" + "let c = '{char}'" + "\"" + "\\034" + "\\x22" + "\\u0022" + "\\U00000022" + // Note: Just check from `'"` to number forms. + // Other directions produce unescaped quotation mark + // -> Handled in test above + check server "can convert escaped double quotation mark" + "let c = '\"$0'" + "" + "let c = '\\034'" + "let c = '\\x22'" + "let c = '\\u0022'" + "let c = '\\U00000022'" + testList "byte" [ let checkAll server