parser: disable template variables in `<style>` (#9777)

pull/9793/head
涂紳騰(Shen-Teng Tu) 2021-04-17 20:47:36 +08:00 committed by GitHub
parent ded3ce5863
commit 3c72c6abc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View File

@ -218,6 +218,10 @@ mut sb := strings.new_builder($lstartlength)\n
// replace `$` to `\$` at first to escape JavaScript template literal syntax // replace `$` to `\$` at first to escape JavaScript template literal syntax
source.writeln(line.replace(r'$', r'\$').replace(r'$$', r'@').replace(r'.$', source.writeln(line.replace(r'$', r'\$').replace(r'$$', r'@').replace(r'.$',
r'.@').replace(r"'", r"\'")) r'.@').replace(r"'", r"\'"))
} else if state == .css {
// disable template variable declaration in inline stylesheet
// because of some CSS rules prefixed with `@`.
source.writeln(line.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

View File

@ -6,6 +6,11 @@
h1 { h1 {
color: green; color: green;
} }
@keyframes mymove {
from {top: 0px;}
to {top: 200px;}
}
</style> </style>
<style media="print"> <style media="print">
h1 { h1 {

View File

@ -6,6 +6,11 @@
h1 { h1 {
color: green; color: green;
} }
@keyframes mymove {
from {top: 0px;}
to {top: 200px;}
}
</style> </style>
<style media="print"> <style media="print">
h1 { h1 {