How to deal with input strings containing the default escape character \
#465
Replies: 3 comments 3 replies
-
Is this issue kind of the same problem as Issue 200? Jacob Mogensen |
Beta Was this translation helpful? Give feedback.
-
The exception is causes by a disallowed escape sequence - There are 2 alternatives so resolve this issue, especially when the input string is not under your control: 1. Disable conversion of character string literals:Smart.Default.Settings.Parser.ConvertCharacterStringLiterals = false;
var result = Smart.Format(@"abc\MSD");
// result is ""abc\MSD" 2. Choose another escape character (it must not interfere with other reserved characters like
|
Beta Was this translation helpful? Give feedback.
-
Hey @axunonb Actually, it did help me understand why SmartFormat behave like it does. The verbatime string
is actually the string
and
is actually the string
The string value is localhost\MSSQL2019, and is written in C# a When that valid string is formatted by SmartFormat, it will result in the error. SmartFormat by default, tries to fix a 'wrong' input (verbatime) string, and replace two backslashes with one backslash, and thereby resulting in an error. I have nothing against that feature. I do like it and can see its value. My problem is that it is enabled by default. If users of SmartFormat use verbatim string, and thereby sending a ''wrong'' string to SmartFormat, and the users want SmartFormat to fix it, they should enable that feature. It should not be the other way around. Correct use of string values should NOT be the one to disable a feature. |
Beta Was this translation helpful? Give feedback.
-
Hi! Thanks for reporting this bug!
Please fill in the relevant information from this template so that we can help you best.
Smart.Format version: 3.5.3
Framework version: net8.0
Microsoft Visual Studio Professional 2022, Version 17.12.4
What is the current result?
Two excaped backslash is reduced to one excaped backslash.
One excaped backslash is seen as a escape charater, and will throw the exception 'Unrecognized escape sequence "\M" in literal.'
What is the expected result?
That Smart.Format did not change the value / can handle a text string with a backslash.
Please post full exception details if applicable (message, stacktrace, inner exceptions)
Did you find a workaround? yes/no
No.
Is there a version in which it worked?
Don't know
Can you help us by writing an unit test?
This illustrate the problem, that two excaped backslash is reduced to one excaped backslash
This demonstrate who Smart.Format, first reduce the two excaped backslash to one, and then see excaped backslash, as a escape charater.
Jacob Mogensen
mySupply ApS
Denmark
Beta Was this translation helpful? Give feedback.
All reactions