diff --git a/src/Fantomas.Tests/SynConstTests.fs b/src/Fantomas.Tests/SynConstTests.fs index 13026c0c5e..7b7c1ebeed 100644 --- a/src/Fantomas.Tests/SynConstTests.fs +++ b/src/Fantomas.Tests/SynConstTests.fs @@ -301,13 +301,11 @@ 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" """ [] @@ -519,3 +517,27 @@ __SOURCE_DIRECTORY__ """ __SOURCE_DIRECTORY__ """ + +[] +let ``escape sequences in strings are preserved`` () = + formatSourceString + false + """let alert = "Hello\aWorld" +let backspace = "Hello\bWorld" +let formFeed = "Hello\fWorld" +let newline = "Hello\nWorld" +let carriageReturn = "Hello\rWorld" +let tab = "Hello\tWorld" +let verticalTab = "Hello\vWorld" +""" + config + |> should + equal + """let alert = "Hello\aWorld" +let backspace = "Hello\bWorld" +let formFeed = "Hello\fWorld" +let newline = "Hello\nWorld" +let carriageReturn = "Hello\rWorld" +let tab = "Hello\tWorld" +let verticalTab = "Hello\vWorld" +""" diff --git a/src/Fantomas/TokenParser.fs b/src/Fantomas/TokenParser.fs index 76f04706a4..45d993196e 100644 --- a/src/Fantomas/TokenParser.fs +++ b/src/Fantomas/TokenParser.fs @@ -530,7 +530,7 @@ let private (|InterpStringEndOrPartToken|_|) token = None let escapedCharacterRegex = - System.Text.RegularExpressions.Regex("(\\\\(a|b|f|n|r|u|v|x|'|\\\"|\\\\))+") + System.Text.RegularExpressions.Regex("(\\\\(a|b|f|n|r|t|u|v|x|'|\\\"|\\\\))+") let rec private (|EndOfInterpolatedString|_|) tokens = match tokens with