Deprecate rather than disallow raw newlines in strings.

Closes #1302
This commit is contained in:
Nathan Weizenbaum
2014-07-11 13:29:58 -07:00
parent c15df3e140
commit e8b1fb7ef9
3 changed files with 31 additions and 4 deletions

View File

@@ -187,8 +187,9 @@ adding multiple suffixes to the same parent selector. For example:
!global` will assign to `$var` globally. This behavior can be detected using
`feature-exists(global-variable-shadowing)`.
* SassScript strings in SCSS may no longer include unescaped newlines. As doing
so produced invalid CSS, there will be no deprecation period for this change.
* Unescaped newlines in SassScript strings in SCSS are deprecated, since they're
invalid according to the CSS string grammar. To include a newline in a string,
use "\a" or "\a " as in CSS.
## 3.3.9 (27 June 2014)

View File

@@ -106,7 +106,7 @@ module Sass
private
def string_re(open, close)
/#{open}((?:\\.|\#(?!\{)|[^#{close}\n\\#])*)(#{close}|#\{)/m
/#{open}((?:\\.|\#(?!\{)|[^#{close}\\#])*)(#{close}|#\{)/m
end
end
@@ -275,7 +275,16 @@ module Sass
end
def string(re, open)
line, offset = @line, @offset
return unless scan(STRING_REGULAR_EXPRESSIONS[re][open])
if @scanner[0] =~ /([^\\]|^)\n/
Sass::Util.sass_warn <<MESSAGE
DEPRECATION WARNING on line #{line}, column #{offset}#{" of #{@filename}" if @filename}:
Unescaped multiline strings are deprecated and will be removed in a future version of Sass.
To include a newline in a string, use "\\a" or "\\a " as in CSS.
MESSAGE
end
if @scanner[2] == '#{' # '
@scanner.pos -= 2 # Don't actually consume the #{
@offset -= 2

View File

@@ -3436,7 +3436,24 @@ bang";
bar: $var;
}
SCSS
end
end
def test_raw_newline_warning
assert_warning(<<MESSAGE.rstrip) {assert_equal(<<CSS, render(<<SCSS))}
DEPRECATION WARNING on line 2, column 9:
Unescaped multiline strings are deprecated and will be removed in a future version of Sass.
To include a newline in a string, use "\\a" or "\\a " as in CSS.
MESSAGE
.foo {
bar: "baz\\a bang"; }
CSS
.foo {
$var: "baz
bang";
bar: $var;
}
SCSS
end
# Regression