Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformation Damages Values with ">" in Them #263

Open
vppetrov opened this issue Aug 29, 2022 · 2 comments
Open

Transformation Damages Values with ">" in Them #263

vppetrov opened this issue Aug 29, 2022 · 2 comments

Comments

@vppetrov
Copy link

I am using transformations for nlog.config and I have some conditions that check the length of the thread name using the ">" symbol. slow-cheetah changes these even with no transformation at all. Here is an example:

nlog.config:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<targets>
		<target name="coloredConsole" xsi:type="ColoredConsole"
				layout="${when:when=length('${threadname}') > 0:inner=/${threadname}}:	${message}"
		/>
	</targets>
	<rules>
		<logger name="*" minlevel="Trace" writeTo="coloredConsole" />
	</rules>
</nlog>

nlog.Debug.config (no transformations at all):

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="http://www.nlog-project.org/schemas/NLog.xsd">
</nlog>

Result:

<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<targets>
		<target name="coloredConsole" xsi:type="ColoredConsole"
				layout="${when:when=length('${threadname}') &gt; 0:inner=/${threadname}}:	${message}"
		/>
	</targets>
	<rules>
		<logger name="*" minlevel="Trace" writeTo="coloredConsole" />
	</rules>
</nlog>

Notice the &gt; in the layout property.

The simplest solution would be to not touch any values that have no transformation applied.

@CZEMacLeod
Copy link

&gt; is the escaped version of > and should be used anywhere you need a > symbol in xml. You can use the unescaped version in some circumstances - such as in an attribute value, but generally it should be avoided.
It is not 'damaged' as an xml parser will correctly unescape the attribute value when it is read.

I'm reasonably certain that the way transforms are done, the whole document is loaded by a parser, then transformed then written back out, so while the specific node won't be touched if no transform is applied, the whole file is written back out with full escaping applied.

@vppetrov
Copy link
Author

@CZEMacLeod Thanks for the comment, makes sense. Seems to be working as well. All nlog samples seem to use > without escapting it which lead to this confusion but it's a problem of these samples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants