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

HTML script tags in x-code-samples JavaScript error #563

Closed
ntrepid8 opened this issue Jul 16, 2018 · 3 comments
Closed

HTML script tags in x-code-samples JavaScript error #563

ntrepid8 opened this issue Jul 16, 2018 · 3 comments

Comments

@ntrepid8
Copy link

I'm trying to provide some HTML code samples in an OpenAPIv3 document using x-code-samples like this:

      x-code-samples:
        - lang: HTML
          source: |
            <head>
                <title>Your title goes here</title>
            </head>

If I add a script tag it seems to break the page rendering:

      x-code-samples:
        - lang: HTML
          source: |
            <head>
                <title>Your title goes here</title>
                <script type="text/javascript" src="https://link.to-script.com/"></script>
            </head>

A bunch of text is dumped at the bottom of the page and I see this error in the console in Firefox 61:

SyntaxError: "" literal not terminated before end of script

I'm using redoc-cli version 0.5.0 on Ubuntu 18.04:

$ redoc-cli --version
0.5.0

I'm using the bundle sub-command:

$ redoc-cli bundle openapi-spec.json --title my-title --output openapi-docs.html

Am I doing something wrong? Or should I be altering the script tag somehow to "escape" it for the code samples?

@ntrepid8
Copy link
Author

With further investigation it seems like it's the closing </script> tag that's causing the issue. If I use this pattern the error goes away:

            <head>
                <title>Your title goes here</title>
                <script><\/script>
            </head>

Looking more at the HTML it seems like the operation being interrupted is the assignment of this value:

<script>
const __redoc_state = {"foo": "bar", ...
</script>

It seems like the </script> tag from my example code is being interpreted as the closing tag for the <script> tag that comes just before const __redoc_state =.

@ntrepid8
Copy link
Author

It's a bit strange but it seems like adding these commented out HTML comments would fix the issue:

<script>
/*<!--*/
const __redoc_state = {"foo": "bar", ...
/*-->*/
</script>

Thoughts?

@RomanHotsiy
Copy link
Member

Thanks for the investigation!
It helped me find a lot!

I will release a new version soon

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

2 participants