Browse files

Ignore CSS namespaces in theme tests

  • Loading branch information...
1 parent eb98cc4 commit c4ab6760c0af0210f76babb065ba488c16e1083b @mattbasta mattbasta committed Feb 11, 2013
Showing with 29 additions and 1 deletion.
  1. +18 −0 tests/test_themes.py
  2. +11 −1 validator/testcases/markup/csstester.py
View
18 tests/test_themes.py
@@ -51,3 +51,21 @@ def test_remote_css():
err.detected_type = PACKAGE_THEME
csstester.test_css_snippet(err, "x.css", snippet, 0)
assert err.failed()
+
+
+def test_remote_css_ignored():
+ """Test that suspicious but innocuous css-isms are ignored."""
+
+ snippet = """
+ @namespace url(http://foo.bar/asdf);
+ @namespace url("http://foo.bar/asdf");
+ """
+
+ err = ErrorBundle()
+ csstester.test_css_snippet(err, "x.css", snippet, 0)
+ assert not err.failed()
+
+ err = ErrorBundle()
+ err.detected_type = PACKAGE_THEME
+ csstester.test_css_snippet(err, "x.css", snippet, 0)
+ assert not err.failed()
View
12 validator/testcases/markup/csstester.py
@@ -71,6 +71,8 @@ def _run_css_tests(err, tokens, filename, line_start=0, context=None):
identity_box_mods = []
unicode_errors = []
+ token_history = []
+
while True:
try:
@@ -84,6 +86,8 @@ def _run_css_tests(err, tokens, filename, line_start=0, context=None):
if tok_type in SKIP_TYPES:
continue
+ token_history.append((tok_type, value))
+
# Save the last descriptor for reference.
if tok_type in ("IDENT", "FUNCTION"):
value_lower = value.lower()
@@ -101,6 +105,8 @@ def _run_css_tests(err, tokens, filename, line_start=0, context=None):
elif tok_type == "URI":
+ print token_history
+
# If we hit a URI after -moz-binding, we may have a
# potential security issue.
if last_descriptor == "-moz-binding" and BAD_URL.match(value):
@@ -116,7 +122,11 @@ def _run_css_tests(err, tokens, filename, line_start=0, context=None):
filename=filename,
line=line + line_start,
context=context.get_context(line))
- elif err.detected_type == PACKAGE_THEME and REM_URL.match(value):
+ elif (err.detected_type == PACKAGE_THEME and
+ REM_URL.match(value) and
+ token_history[-2][0] != 'NAMESPACE_SYM'):
+ # If we're a theme and the URL is remote and the last token
+ # wasn't a CSS namespace symbol, raise a warning.
err.warning(
err_id=("css", "_run_css_tests", "remote_url"),
warning="Themes may not reference remote resources",

0 comments on commit c4ab676

Please sign in to comment.