From f828c652049a8d558b06c613d5a7261bd973ab96 Mon Sep 17 00:00:00 2001 From: vain0x Date: Sun, 7 Mar 2021 02:13:59 +0900 Subject: [PATCH] Keep hex escapes in string literals (#1508) (#1509) * Keep hex escapes in string literals (#1508) * Add more patterns to escapedCharacterRegex (#1508) --- src/Fantomas.Tests/SynConstTests.fs | 14 ++++++++++++++ src/Fantomas/TokenParser.fs | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Fantomas.Tests/SynConstTests.fs b/src/Fantomas.Tests/SynConstTests.fs index 0f8d53a692..4834c786e3 100644 --- a/src/Fantomas.Tests/SynConstTests.fs +++ b/src/Fantomas.Tests/SynConstTests.fs @@ -294,3 +294,17 @@ let f (c: char) = | '\u0000' | _ -> () """ + +[] +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" +""" diff --git a/src/Fantomas/TokenParser.fs b/src/Fantomas/TokenParser.fs index e14fe4b72b..633023253c 100644 --- a/src/Fantomas/TokenParser.fs +++ b/src/Fantomas/TokenParser.fs @@ -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