parser: escape js template literal syntax inside <script> tags (#9738)
parent
cb69c4c91a
commit
d9fdae1de9
|
@ -214,11 +214,15 @@ mut sb := strings.new_builder($lstartlength)\n
|
||||||
} else {
|
} else {
|
||||||
source.writeln('</div>')
|
source.writeln('</div>')
|
||||||
}
|
}
|
||||||
|
} else if state == .js {
|
||||||
|
// replace `$` to `\$` at first to escape JavaScript template literal syntax
|
||||||
|
source.writeln(line.replace(r'$', r'\$').replace(r'$$', r'@').replace(r'.$',
|
||||||
|
r'.@').replace(r"'", r"\'"))
|
||||||
} else {
|
} else {
|
||||||
// HTML, may include `@var`
|
// HTML, may include `@var`
|
||||||
// escaped by cgen, unless it's a `vweb.RawHtml` string
|
// escaped by cgen, unless it's a `vweb.RawHtml` string
|
||||||
source.writeln(line.replace('@', '$').replace('$$', '@').replace('.$', '.@').replace("'",
|
source.writeln(line.replace(r'@', r'$').replace(r'$$', r'@').replace(r'.$',
|
||||||
"\\'"))
|
r'.@').replace(r"'", r"\'"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
source.writeln(parser.tmpl_str_end)
|
source.writeln(parser.tmpl_str_end)
|
||||||
|
|
|
@ -17,6 +17,9 @@ color: red;
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
document.getElementById("demo").innerHTML = "Hello JavaScript!";
|
document.getElementById("demo").innerHTML = "Hello JavaScript!";
|
||||||
|
|
||||||
|
const classes = `header ${ isLargeScreen() ? '' :
|
||||||
|
`icon-${item.isCollapsed ? 'expander' : 'collapser'}` }`;
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ color: red;
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
document.getElementById("demo").innerHTML = "Hello JavaScript!";
|
document.getElementById("demo").innerHTML = "Hello JavaScript!";
|
||||||
|
|
||||||
|
const classes = `header ${ isLargeScreen() ? '' :
|
||||||
|
`icon-${item.isCollapsed ? 'expander' : 'collapser'}` }`;
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue