Skip to content

Commit

Permalink
Fix incorrect CSS string detection
Browse files Browse the repository at this point in the history
Closes #81
  • Loading branch information
JaapJoris committed Feb 23, 2023
1 parent 342c61f commit 3cb16e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
4 changes: 2 additions & 2 deletions djhtml/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ class DjCSS(DjTXT):
r"</style>",
r"[{()}]",
r"/\*",
r'".+"',
r"'.+'",
r'"(?:\\.|[^\\"])*"', # "string"
r"'(?:\\.|[^\\'])*'", # 'string'
r"[\w-]+: ",
r";",
]
Expand Down
7 changes: 7 additions & 0 deletions tests/suite/css.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,10 @@
Helvetica;
}
</style>


<!-- Nasty characters embedded in strings -->
<style>
foo: "\"bar";
.icon-x-alarm:before { content: '\e800'; } /* '' */
</style>
23 changes: 15 additions & 8 deletions tests/suite/css.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ Line([Text(' @font-face ', mode=DjCSS), Open('{', mode=DjCSS, level=1)], leve
Line([Text(' ', mode=DjCSS), Text('font-family: ', mode=DjCSS), Text("'Open Sans'", mode=DjCSS, absolute=13), Text(';', mode=DjCSS)], level=2)
Line([Text(' ', mode=DjCSS), Text('font-style: ', mode=DjCSS), Text('normal', mode=DjCSS, absolute=12), Text(';', mode=DjCSS)], level=2)
Line([Text(' ', mode=DjCSS), Text('font-weight: ', mode=DjCSS), Text('normal', mode=DjCSS, absolute=13), Text(';', mode=DjCSS)], level=2)
Line([Text(' ', mode=DjCSS), Text('src: ', mode=DjCSS), Text('url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Open_Sans.woff2') format('woff2'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=2)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Open_Sans.woff') format('woff'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=2, offset=5)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Open_Sans.eot?#iefix') format('embedded-opentype'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=2, offset=5)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Open_Sans.svg#OpenSans') format('svg'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=2, offset=5)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Open_Sans.ttf') format('truetype'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(';', mode=DjCSS)], level=2, offset=5)
Line([Text(' ', mode=DjCSS), Text('src: ', mode=DjCSS), Text('url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Open_Sans.woff2'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(' format', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'woff2'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=2)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Open_Sans.woff'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(' format', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'woff'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=2, offset=5)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Open_Sans.eot?#iefix'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(' format', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'embedded-opentype'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=2, offset=5)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Open_Sans.svg#OpenSans'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(' format', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'svg'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=2, offset=5)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Open_Sans.ttf'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(' format', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'truetype'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(';', mode=DjCSS)], level=2, offset=5)
Line([Text(' ', mode=DjCSS), Close('}', mode=DjCSS)], level=1)
Line([Close('</style>', mode=DjHTML)])
Line([])
Expand All @@ -58,10 +58,10 @@ Line([Text('<', mode=DjHTML), Text('style', mode=InsideHTMLTag, absolute=7), Ope
Line([Text(' @font-face ', mode=DjCSS), Open('{', mode=DjCSS, level=1)], level=1)
Line([Text(' ', mode=DjCSS), Text('font-family: ', mode=DjCSS), Text('Helvetica', mode=DjCSS, absolute=13), Text(';', mode=DjCSS)], level=2)
Line([Text(' ', mode=DjCSS), Text('src: ', mode=DjCSS), Open('{% for format, filename in licensed_fonts %}', mode=DjTXT, level=2, absolute=5)], level=2)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=3, absolute=5), Text("'{% static filename %}') format('{{ format }}'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=3, offset=5)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=3, absolute=5), Text("'{% static filename %}'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(' format', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=3, absolute=5), Text("'{{ format }}'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=3, offset=5)
Line([Text(' ', mode=DjCSS, absolute=5), Close('{% endfor %}', mode=DjTXT, absolute=5)], level=2, offset=5)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Arial.woff2') format('woff2'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=2, offset=5)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Arial.woff') format('woff'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(';', mode=DjCSS)], level=2, offset=5)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Arial.woff2'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(' format', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'woff2'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(',', mode=DjCSS, absolute=5)], level=2, offset=5)
Line([Text(' url', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'Arial.woff'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(' format', mode=DjCSS, absolute=5), Open('(', mode=DjCSS, level=2, absolute=5), Text("'woff'", mode=DjCSS, absolute=5), Close(')', mode=DjCSS, absolute=5), Text(';', mode=DjCSS)], level=2, offset=5)
Line([Text(' ', mode=DjCSS), Close('}', mode=DjCSS)], level=1)
Line([Close('</style>', mode=DjHTML)])
Line([])
Expand Down Expand Up @@ -187,4 +187,11 @@ Line([Text(' ', mode=DjCSS), Text('color: ', mode=DjCSS), Text('red', mod
Line([Text(' Helvetica', mode=DjCSS, absolute=27), Text(';', mode=DjCSS)], level=2, offset=27)
Line([Text(' ', mode=DjCSS), Close('}', mode=DjCSS)], level=1)
Line([Close('</style>', mode=DjHTML)])
Line([])
Line([])
Line([Open('<!--', mode=DjHTML, ignore=True), Text(' Nasty characters embedded in strings ', mode=Comment, ignore=True), Close('-->', mode=DjHTML, ignore=True)], ignore=True)
Line([Text('<', mode=DjHTML), Text('style', mode=InsideHTMLTag, absolute=7), Open('>', mode=DjHTML)])
Line([Text(' ', mode=DjCSS), Text('foo: ', mode=DjCSS), Text('"\\"bar"', mode=DjCSS, absolute=5), Text(';', mode=DjCSS)], level=1)
Line([Text(' .icon-x-alarm:before ', mode=DjCSS), Open('{', mode=DjCSS, level=1), Text(' ', mode=DjCSS), Text('content: ', mode=DjCSS), Text("'\\e800'", mode=DjCSS, absolute=32), Text(';', mode=DjCSS), Text(' ', mode=DjCSS), Close('}', mode=DjCSS), Text(' ', mode=DjCSS), Open('/*', mode=DjCSS, level=1, ignore=True), Text(" '\ue800' ", mode=Comment, ignore=True), Close('*/', mode=DjCSS, ignore=True)], level=1)
Line([Close('</style>', mode=DjHTML)])
Line([])

0 comments on commit 3cb16e1

Please sign in to comment.