Commit 99abda3d authored by huangs's avatar huangs

[Presubmit] Make CSS checker ignore '@' inside of strings.

This fixes the bug where url('google_logo.png@2x') causes validation
failures.

BUG=408759
R=dbeam@chromium.org

Review URL: https://codereview.chromium.org/514403002

Cr-Commit-Position: refs/heads/master@{#293603}
parent 2eea4348
......@@ -455,15 +455,20 @@ class CssStyleGuideTest(SuperMoxTestBase):
self.mox.StubOutWithMock(self.output_api, 'PresubmitPromptWarning',
use_mock_anything=True)
author_msg = ('Was the CSS checker useful? '
'Send feedback or hate mail to dbeam@chromium.org.')
self.output_api = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(self.output_api, 'PresubmitNotifyResult',
use_mock_anything=True)
self.output_api.PresubmitNotifyResult(author_msg).AndReturn(None)
def VerifyContentsIsValid(self, contents):
self.fake_file.NewContents().AndReturn(contents.splitlines())
self.mox.ReplayAll()
css_checker.CSSChecker(self.input_api, self.output_api).RunChecks()
def VerifyContentsProducesOutput(self, contents, output):
self.fake_file.NewContents().AndReturn(contents.splitlines())
author_msg = ('Was the CSS checker useful? '
'Send feedback or hate mail to dbeam@chromium.org.')
self.output_api.PresubmitNotifyResult(author_msg).AndReturn(None)
self.output_api.PresubmitPromptWarning(
self.fake_file_name + ':\n' + output.strip()).AndReturn(None)
self.mox.ReplayAll()
......@@ -508,6 +513,24 @@ class CssStyleGuideTest(SuperMoxTestBase):
z-index: 5;
color: black;""")
def testCssStringWithAt(self):
self.VerifyContentsIsValid("""
#logo {
background-image: url('images/google_logo.png@2x');
}
body.alternate-logo #logo {
-webkit-mask-image: url('images/google_logo.png@2x');
background: none;
}
.stuff1 {
}
.stuff2 {
}
""")
def testCssAlphaWithNonStandard(self):
self.VerifyContentsProducesOutput("""
div {
......
......@@ -33,9 +33,9 @@ class CSSChecker(object):
def _remove_ats(s):
at_reg = re.compile(r"""
@\w+.*?{ # @at-keyword selector junk {
(.*{.*?})+ # inner { curly } blocks, rules, and selector junk
.*?} # stuff up to the first end curly }""",
@\w+[^'"]*?{ # @at-keyword selector junk {
(.*{.*?})+ # inner { curly } blocks, rules, and selector junk
.*?} # stuff up to the first end curly }""",
re.DOTALL | re.VERBOSE)
return at_reg.sub('\\1', s)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment