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

Reduced risk of false positives #1

Merged
merged 1 commit into from
Jul 14, 2014
Merged

Conversation

OverZealous
Copy link
Collaborator

Reduced risk of false positives for inserting the script by making the html regex stricter, adding many more filetypes to the default exclusion list, and adjusting the html/rules tests. Fixes BrowserSync/browser-sync#198

These are the changes I've made to help reduce the risk of accidentally corrupting a non-html file:

  • Increased the list of ignore types significantly. The new list should cover just about any form of file you'd expect to see served, and then some. It may be too aggressive, feel free to have me remove some if needed.

  • Increased the robustness of the html-test regex. The new regex requires an html-like tag to be the first non-whitespace character. It also allows for byte order marks, although I'm not sure if that's necessary.

  • I changed the order of the tests for injection. The original test went something like:

    1. Does it have one of the rules?
      • If so, replace the content matched by the rule
    2. Is it HTML?
      • If so, assume we need to append the content
    3. Otherwise do nothing.

    The problem is that non-html files might contain the rule, and end up being modified, which doesn't make much sense. The new logic is this:

    1. Is it HTML?
      • Does it have one of the rules?
        • If so, replace the content matched by the rule
      • Otherwise, assume we need to append the content
    2. Otherwise do nothing.

    This ensures that only content that looks like HTML will get modified.

I also rewrote the binary tests to allow for easily adding static tests of various files. I added a few new files to test, including a random binary blob that includes <html> in the middle, and several JSON files with html content, to make sure they don't get modified.

I ran the new tests with and without the new HTML regex and testing order, to ensure they are able to correctly test the results.

All other tests were left unmodified, and everything is passing.

…e html regex stricter, adding many more filetypes to the default exclusion list, and adjusting the html/rules tests. Fixes BrowserSync/browser-sync#198
@shakyShane
Copy link
Owner

Now THIS is why I love Open Source - great work!

This looks flawless to me - I'll give it a good test in some real-world projects before we merge, but this is really great.

It would be nice to get this into BrowserSync 1.3.0 which also has HTTPS support - so we're making big steps forward now. :)

Many thanks :)

shakyShane added a commit that referenced this pull request Jul 14, 2014
Reduced risk of false positives
@shakyShane shakyShane merged commit 4b2a9cc into shakyShane:master Jul 14, 2014
@shakyShane
Copy link
Owner

I think you can really push this module further and make it the best-in-class. Would you like commit access? That way you can work on branches and I can swoop in to do the releases when needed?

@OverZealous
Copy link
Collaborator Author

Sure, I'd be happy to. I'll probably wait to make any changes until I there is some feedback.

@shakyShane
Copy link
Owner

Of course :)

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

Successfully merging this pull request may close these issues.

Browser-sync corrupting MP3 files when serving them
2 participants