mirror of
https://github.com/Redocly/redoc.git
synced 2025-03-03 17:35:46 +03:00
fix(cli): cli output crashes if script closing tag is in the spec
fixes #563
This commit is contained in:
parent
32df7767fd
commit
76906eb126
11
cli/index.ts
11
cli/index.ts
|
@ -236,7 +236,7 @@ async function getPageHTML(
|
||||||
redocHTML: `
|
redocHTML: `
|
||||||
<div id="redoc">${(ssr && html) || ''}</div>
|
<div id="redoc">${(ssr && html) || ''}</div>
|
||||||
<script>
|
<script>
|
||||||
${(ssr && `const __redoc_state = ${escapeUnicode(JSON.stringify(state))};`) || ''}
|
${(ssr && `const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};`) || ''}
|
||||||
|
|
||||||
var container = document.getElementById('redoc');
|
var container = document.getElementById('redoc');
|
||||||
Redoc.${
|
Redoc.${
|
||||||
|
@ -306,6 +306,15 @@ function isURL(str: string): boolean {
|
||||||
return /^(https?:)\/\//m.test(str);
|
return /^(https?:)\/\//m.test(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sanitizeJSONString(str: string) {
|
||||||
|
return escapeClosingScriptTag(escapeUnicode(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
|
||||||
|
function escapeClosingScriptTag(str) {
|
||||||
|
return str.replace(/<\/script>/g, '<\\/script>');
|
||||||
|
}
|
||||||
|
|
||||||
// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
|
// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
|
||||||
function escapeUnicode(str) {
|
function escapeUnicode(str) {
|
||||||
return str.replace(/\u2028|\u2029/g, m => '\\u202' + (m === '\u2028' ? '8' : '9'));
|
return str.replace(/\u2028|\u2029/g, m => '\\u202' + (m === '\u2028' ? '8' : '9'));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user