htmldiff.net
htmldiff.net copied to clipboard
Script tags should be ignored
script starts cssConstPopupClose = "nice"; var css = css || {}; css.archive = {}; css.archive.serverUrl = "https://google.com.au"; css.archive.disabled = false; css.archive.tenant = "css-lhb"; css.archive.mock = false; ends script 2) script starts cssConstPopupClose = "nice"; var css = css || {}; css.archive = {}; css.archive.serverUrl = "https://google.com.au"; css.archive.disabled = false; css.archive.tenant = "sanagate-lhb"; css.archive.mock = false; ends script
If you compare those two versions then the result is:
script starts
cssConstPopupClose = "nice";
var css = css || {};
css.archive = {};
css.archive.serverUrl = "https://google.com.au";
css.archive.disabled = false;
css.archive.tenant = "css"sanagate-lhb";
css.archive.mock = false;
ends script
This results in a javascript error and the comparison cannot be seen.
I have a very rudimentary fix for this:
private static bool IsEndOfTag(string val, string currentWord)
{
return val == ">"
&& (!currentWord.StartsWith("<script", StringComparison.OrdinalIgnoreCase)
|| (currentWord.StartsWith("<script", StringComparison.OrdinalIgnoreCase)
&& currentWord.ToLower().Contains("</script")));
}
And then change the ConvertHtmlToListOfWords
to to pass in the current word:
case DiffMode.Tag:
if (IsEndOfTag(character, currentWord))
{
This will at least collect the entire script tag as a word which can be diff'd. Problem is, if you are rendering the diff'd HTML, and you have the <del>
and <ins
> tags wrapped around your tags, the script tag is still intact, so will execute twice on the page.e.g:
<script>console.log('first');</script>
and
<script>console.log('second');</script>
Will result in
<del class='diffmod'><script>console.log('first');</script></del><ins class='diffmod'><script>console.log('second');</script></ins>
Not sure how best to handle that, but then that's probably not this libraries responsibility.
why shouldn't it be this libraries responsibility @Antaris?