-->

Stop Sparkview escaping html

2019-09-16 04:15发布

问题:

I am trying to output some HTML video tags park of which include

<source src="${Model.WebMFilename}" type='video/webm; codecs="vp8, vorbis"' />

However in the browser this renders as

<source vorbis""="" vp8,="" type="video/webm; codecs=" src="VP8_645001.webm"></source>

Any idea how I stop Sparkview reformatting the output?

回答1:

Are you sure about your output? I ran this exact scenario through a unit test in the source code and I got the following:

Input:

<source src="${Model.WebMFilename}" type='video/webm; codecs="vp8, vorbis"' />

Result:

<source src="VP8_645001.webm"  type="video/webm; codecs="vp8, vorbis"" />

This looks like a "feature" in Spark is getting in the way here, and this is becoming more prevalent with client side frameworks, json popularity and HTML5 attributes usage.

The "feature" I speak of is that Spark can read your input and you can have single or double quotes surrounding your attributes and it will understand the value inside the attribute without an issue, but there is a current side effect of view compilation that automatically (and incorrectly) replaces the surrounding attributes with double quote instead of the quote type you actually used.

I am currently working on a fix for this in the source code. In the mean time, you could try and place your double quotes on the outside of the attribute and try single quotes on the inside although I know this does break some of the client side frameworks since they don't expect that. Can you try this instead (Note: single quote on the inside):

<source src="${Model.WebMFilename}" type="video/webm; codecs='vp8, vorbis'" />

Hope that helps,
Rob



回答2:

I managed to get the desired output by wrapping the single quote !{"'"} so

<source src="${Model.WebMFilename}" type=!{"'"}video/webm; codecs="vp8, vorbis"!{"'"} />

Rendered

<source src="VP8_645001.webm" type='video/webm; codecs="vp8, vorbis"' />