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

Update Browsersync snippet regex to use a lookbehind #2227

Merged
merged 1 commit into from Dec 17, 2019

Conversation

fitztrev
Copy link
Contributor

@fitztrev fitztrev commented Sep 18, 2019

The current regex is /(<\/body>|<\/pre>)/i so it will find either the first </body> or </pre> tag, but it should really find the last.

This PR adds a lookbehind to the regex to grab the last one instead.

This would be the effect of this change on a page that contains a </pre> and a </body>:

<html>
<body>
    <pre>
--        <script src="browsersync.js"></script>
    </pre>
++  <script src="browsersync.js"></script>
</body>
</html>

Fixes #2239
Fixes laravel/framework#29909
Fixes laravel/framework#30018
Fixes facade/ignition#16
Fixes BrowserSync/browser-sync#1459

@fitztrev
Copy link
Contributor Author

I run into the issue because vue.js throws an error when you have a <script> tag inside one of its DOM elements:

new Vue({
    el: '#app'
})
<body>
    <div id="app">
        <pre>
            some preformatted code here
        </pre>
    </div>
</body>

This PR will fix it so that the <script> is no longer inside the #app element.

<body>
    <div id="app">
        <pre>
            some preformatted code here
--          <script src="browsersync.js"></script>
        </pre>
    </div>
++  <script src="browsersync.js"></script>
</body>

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