Preventing SlowCheetah from encoding "<", ">" and adding &#xD;&#xA; for carriage returns

561 views Asked by At

I am using SlowCheetah for transforming my application config file. My problem is that some of the values that it replaces are SQL statements that have conditions like ... where x > 1 and the > ends up being encoded as &gt;, \r\n ends up as &#xD;&#xA; and so forth. If I send this sort of statement to the database will throw an error.

How do I prevent this? I googled already with no luck.

3

There are 3 answers

0
Icarus On BEST ANSWER

To "fix" this issue - if you can call it that - I ended up moving the section that contained the special characters that were being encoded by SlowCheetah to a different file, and set the configSource attribute in the section to point to the new file. Basically, I did this:

<pluginsSection configSource="Configs\pluginsConfig.xml"> 
</pluginSection>

Now SlowCheetah transforms the App.config file and the contents of pluginsConfig.xml are not affected.

1
Alexey Shcherbak On

These symbols are forbidden symbols in XML. Slow Cheetah is using XmlTransformableDocument, which I think inherits from XmlDocument, thus when transformation applied - all non-XML-markup symbols are being encoded, including your ">" signs.

I don't think you can easily fix this behaviour, and not sure why you're using transformations on non-valid XML document.

1
ymz On

in general: placing your sql statements inside a config file (or any unprotected file in that matter) is not such a brilliant idea.. if anyone would ever put their hands on that gile file they will gain priceless information about your database structure and logic.

please consider use stored procedures that hides database logic, names, operators and such (your config will just contain stored procedures calls with parameters - without forbbiden xml chars)

if you still insist to place your sql queries as a plain text - that is why .net has resources... instead of placing those statement inside your condig file, put them inside your project resources (a file with a resx extension)

for winforms applications: Resources, where to put them, and how to reference them in C#

for web applications: http://msdn.microsoft.com/en-us/library/ms247246%28v=vs.100%29.aspx

for libraries (dll files): http://www.codeproject.com/Articles/5447/NET-Localization-using-Resource-file