Skip to content

Commit

Permalink
Fix: Produces unescaped single quotation mark for char
Browse files Browse the repository at this point in the history
Note: Double Quotation marks remain unescaped
  • Loading branch information
Booksbaum committed Sep 18, 2023
1 parent 7b2c9aa commit e6ce3bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/FsAutoComplete/CodeFixes/AdjustConstant.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
26 changes: 26 additions & 0 deletions test/FsAutoComplete.Tests.Lsp/CodeFixTests/AdjustConstantTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e6ce3bc

Please sign in to comment.