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

Script tags should be ignored #11

Open
leonkyr opened this issue Feb 4, 2015 · 2 comments
Open

Script tags should be ignored #11

leonkyr opened this issue Feb 4, 2015 · 2 comments

Comments

@leonkyr
Copy link

leonkyr commented Feb 4, 2015

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.

@Antaris
Copy link

Antaris commented May 29, 2015

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.

@iamdjones
Copy link

why shouldn't it be this libraries responsibility @Antaris?

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

3 participants