Skip to content

Commit

Permalink
Keep hex escapes in string literals (fsprojects#1508) (fsprojects#1509)
Browse files Browse the repository at this point in the history
* Keep hex escapes in string literals (fsprojects#1508)

* Add more patterns to escapedCharacterRegex (fsprojects#1508)
  • Loading branch information
vain0x authored Mar 6, 2021
1 parent ba5b44e commit f828c65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Fantomas.Tests/SynConstTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,17 @@ let f (c: char) =
| '\u0000'
| _ -> ()
"""

[<Test>]
let ``hex escape in string literal should be preserved, 1508`` () =
formatSourceString
false
"""let hexEscape = "\x00"
let controlEscapes = "\a \b \f \v"
"""
config
|> should
equal
"""let hexEscape = "\x00"
let controlEscapes = "\a \b \f \v"
"""
2 changes: 1 addition & 1 deletion src/Fantomas/TokenParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ let private (|InterpStringEndOrPartToken|_|) token =
None

let escapedCharacterRegex =
System.Text.RegularExpressions.Regex("(\\\\(n|r|u|'|\\\"|\\\\))+")
System.Text.RegularExpressions.Regex("(\\\\(a|b|f|n|r|u|v|x|'|\\\"|\\\\))+")

let rec private (|EndOfInterpolatedString|_|) tokens =
match tokens with
Expand Down

0 comments on commit f828c65

Please sign in to comment.