1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Sass] Don't die on interpolation in unrecognized selectors either.

This commit is contained in:
Nathan Weizenbaum 2010-08-08 15:32:34 -07:00
parent 69f812ef17
commit e7b6764093
4 changed files with 24 additions and 6 deletions

View file

@ -7,7 +7,7 @@
[Tagged on GitHub](http://github.com/nex3/haml/commit/3.0.17).
* Disallow `#{}` interpolation in `@media` queries.
* Disallow `#{}` interpolation in `@media` queries or unrecognized directives.
This was never allowed, but now it explicitly throws an error
rather than just producing invalid CSS.

View file

@ -7,6 +7,15 @@ module Sass
# parent references, nested selectors, and so forth.
# It does support all the same CSS hacks as the SCSS parser, though.
class CssParser < StaticParser
# Parse a selector, and return its value as a string.
#
# @return [String, nil] The parsed selector, or nil if no selector was parsed
# @raise [Sass::SyntaxError] if there's a syntax error in the selector
def parse_selector_string
init_scanner!
str {return unless selector}
end
private
def parent_selector; nil; end

View file

@ -109,11 +109,10 @@ module Sass
return dir
end
val = str do
# Most at-rules take expressions (e.g. @import),
# but some (e.g. @page) take selector-like arguments
expr || selector
end
# Most at-rules take expressions (e.g. @import),
# but some (e.g. @page) take selector-like arguments
val = str {break unless expr}
val ||= CssParser.new(@scanner, @line).parse_selector_string
node = node(Sass::Tree::DirectiveNode.new("@#{name} #{val}".strip))
if tok(/\{/)

View file

@ -1013,6 +1013,16 @@ MESSAGE
SCSS
end
def test_no_interpolation_in_unrecognized_directives
assert_raise(Sass::SyntaxError, <<MESSAGE) {render <<SCSS}
Invalid CSS after "@foo ": expected selector or at-rule, was "\#{100} {"
MESSAGE
@foo \#{100} {
foo {bar: baz}
}
SCSS
end
# Regression
def test_weird_added_space