mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: escape js template literal syntax inside <script> tags (#9738)
This commit is contained in:
parent
cb69c4c91a
commit
d9fdae1de9
@ -214,11 +214,15 @@ mut sb := strings.new_builder($lstartlength)\n
|
||||
} else {
|
||||
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 {
|
||||
// HTML, may include `@var`
|
||||
// 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)
|
||||
|
@ -17,6 +17,9 @@ color: red;
|
||||
</script>
|
||||
<script>
|
||||
document.getElementById("demo").innerHTML = "Hello JavaScript!";
|
||||
|
||||
const classes = `header ${ isLargeScreen() ? '' :
|
||||
`icon-${item.isCollapsed ? 'expander' : 'collapser'}` }`;
|
||||
</script>
|
||||
</head>
|
||||
|
||||
|
@ -17,6 +17,9 @@ color: red;
|
||||
</script>
|
||||
<script>
|
||||
document.getElementById("demo").innerHTML = "Hello JavaScript!";
|
||||
|
||||
const classes = `header ${ isLargeScreen() ? '' :
|
||||
`icon-${item.isCollapsed ? 'expander' : 'collapser'}` }`;
|
||||
</script>
|
||||
</head>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user