Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions mincss/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
VENDOR_PREFIXED_PSEUDO_CLASSES = re.compile(
':-(webkit|moz)-'
)
# For matching things like "foo:bar" and '"foo:ing":bar' because it's
# not enough to just do a split on ':' since the ':' might be inside
# quotation marks. E.g. 'a[href^="javascript:"]'
PSEUDO_SELECTOR = re.compile(
r':(?=([^"\'\\]*(\\.|["\']([^"\'\\]*\\.)*[^"\'\\]*[\'"]))*[^"\']*$)'
)

EXCEPTIONAL_SELECTORS = (
'html',
Expand Down Expand Up @@ -504,8 +510,6 @@ def _found(self, bodies, selector):
# If the last part of the selector is a tag like
# ".foo blockquote" or "sometag" then we can look for it
# in plain HTML as a form of optimization
last_part = selector.split()[-1]
# if self._all_tags and '"' not in selector:
if not re.findall('[^\w \.]', selector):
# It's a trivial selector. Like "tag.myclass",
# or ".one.two". Let's look for some cheap wins
Expand All @@ -525,7 +529,7 @@ def _found(self, bodies, selector):
def _simplified_selector(selector):
# If the select has something like :active or :hover,
# then evaluate it as if it's without that pseudo class
return selector.split(':')[0].strip()
return PSEUDO_SELECTOR.split(selector)[0].strip()

def _selector_query_found(self, bodies, selector):
if '}' in selector:
Expand Down
9 changes: 9 additions & 0 deletions tests/complex-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@
<style>
a[href^="javascript:"] { color: pink; }
a[href^="javascript:"]:after { content: "x"; }
.ui[class*="4:3"].embed {
padding-bottom: 75%;
}
.ui[class*="6:9"].embed {
padding-bottom: 95%;
}
</style>
</head>
<body>
<h1>h1</h1>
<a href="javascript:alert('hi')">actually</a>

<div class="ui embed 4:3">
Stuff
</div>
</body>
</html>
2 changes: 2 additions & 0 deletions tests/test_mincss.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ def test_complex_colons_in_selector_expression(self):
after = p.inlines[0].after
ok_('a[href^="javascript:"] { color: pink; }' in after)
ok_('a[href^="javascript:"]:after { content: "x"; }' in after)
ok_('.ui[class*="4:3"].embed' in after)
ok_('.ui[class*="6:9"].embed' not in after)

def test_before_after(self):
html = os.path.join(HERE, 'before-after.html')
Expand Down