universal-vue / uvue

Vue CLI plugin to create universal Vue applications with ease
https://universal-vue.github.io/docs/
MIT License
127 stars 13 forks source link

<script> tag inside window.___DATA___ makes this object broken #46

Closed Grawl closed 4 years ago

Grawl commented 4 years ago

Describe the bug

With </script> in window.__DATA__ there is a parse error:

Uncaught SyntaxError: Invalid or unexpected token

To Reproduce

Make your state look like this:

<script>
window.__DATA__ = {
    'components': [
        {
            'body': 'some HTML with <script src="http://some-url"></script>',
        },
    ],
    'state': {
        'rows': [],
    },
}
</script>

And you will see this HTML is not valid because <script> is closed in the middle of it's content'

Seems like the problem is here:

https://github.com/universal-vue/uvue/blob/c6c421b65151481aafa6523d72b8293b331cfb22/packages/%40uvue/server/src/Renderer.ts#L43

Expected behavior

State loaded without runtime errors

Additional context

node: 12.15.0
vue-cli: 3.12.1
@uvue/core: 0.1.5
@uvue/server: 0.1.3
os: macOS Catalina 10.15.2 (19C57)
browser: Google Chrome 80.0.3987.122
Grawl commented 4 years ago

It's not clear that HTML is broken because of github code highlighter.

If you copy this code into WebStorm, you will see the problem:

изображение
Grawl commented 4 years ago

As a workaround, I will replace all <script> tags to [script] and replace back on client.

yabab-dev commented 4 years ago

Fixed in 0.1.6