From 4e2e1cd2194b683e5dd030a411868b3fcc4a91d7 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 19 Jun 2018 18:28:27 -0700 Subject: [PATCH 1/4] Parse hex colors with alpha channels See sass/sass#2179 --- doc-src/SASS_CHANGELOG.md | 5 +++++ lib/sass/script/lexer.rb | 20 ++++++++------------ lib/sass/script/value/color.rb | 5 +++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index 750c08eef..7c52676f6 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -8,6 +8,11 @@ * Add support for importing an `_index.scss` or `_index.sass` file when importing a directory. +### Backwards Incompatibilities -- Must Read! + +* Tokens such as `#abcd` that are ambiguous between ID strings and hex colors + with an alpha channel are now parsed as colors. + ## 3.5.6 (22 March 2018) * Allow `!` in custom property values. diff --git a/lib/sass/script/lexer.rb b/lib/sass/script/lexer.rb index 7ae7e1114..5fdac73a3 100644 --- a/lib/sass/script/lexer.rb +++ b/lib/sass/script/lexer.rb @@ -368,24 +368,20 @@ def id # IDs in properties are used in the Basic User Interface Module # (http://www.w3.org/TR/css3-ui/). return unless scan(REGULAR_EXPRESSIONS[:id]) - if @scanner[0] =~ /^\#[0-9a-fA-F]+$/ - if @scanner[0].length == 4 || @scanner[0].length == 7 - return [:color, Script::Value::Color.from_hex(@scanner[0])] - elsif @scanner[0].length == 5 || @scanner[0].length == 9 - filename = @options[:filename] - Sass::Util.sass_warn < red, :green => green, :blue => blue, :representation => hex_string} From 987aa687cf52eb4aa4faeb0155f2b8d886b4a5e3 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 20 Jun 2018 20:55:00 -0400 Subject: [PATCH 2/4] Remove tests that assumed four-digit hex colors were invalid --- test/sass/script_test.rb | 2 -- test/sass/value_helpers_test.rb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/test/sass/script_test.rb b/test/sass/script_test.rb index dfd4d0984..d889a6a1f 100644 --- a/test/sass/script_test.rb +++ b/test/sass/script_test.rb @@ -608,8 +608,6 @@ def test_non_ident_colors_with_wrong_number_of_digits 'Invalid CSS after "": expected expression (e.g. 1px, bold), was "#1"') {eval("#1")} assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "": expected expression (e.g. 1px, bold), was "#12"') {eval("#12")} - assert_raise_message(Sass::SyntaxError, - 'Invalid CSS after "": expected expression (e.g. 1px, bold), was "#1234"') {eval("#1234")} assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "": expected expression (e.g. 1px, bold), was "#12345"') {eval("#12345")} assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "": expected expression (e.g. ' \ diff --git a/test/sass/value_helpers_test.rb b/test/sass/value_helpers_test.rb index c8c07fbf5..d4ccea856 100644 --- a/test/sass/value_helpers_test.rb +++ b/test/sass/value_helpers_test.rb @@ -40,7 +40,7 @@ def test_malformed_hex_color hex_color("green") end assert_raises ArgumentError do - hex_color("#abcd") + hex_color("#abcde") end end From c75bb8dc0dbd4d1c04757a04e0b77be3a96d7109 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 21 Jun 2018 14:53:42 -0400 Subject: [PATCH 3/4] Fetch the pull request number using @sassbot's credentials This avoids running into GitHub's low rate limits for unauthenticated requests. --- .travis.yml | 5 +++-- extra/sass-spec-ref.sh | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 96e9b78d2..94a1a134f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,16 @@ sudo: false language: ruby cache: bundler + install: # If we're running for a pull request, check out the revision of sass-spec # referenced by that pull request. - | if [ ! -z "$TRAVIS_PULL_REQUEST" -a "$TRAVIS_PULL_REQUEST" != false ]; then + ref=$(extra/sass-spec-ref.sh) mkdir sass-spec git -C sass-spec init - git -C sass-spec pull --depth=1 git://github.com/sass/sass-spec \ - $(extra/sass-spec-ref.sh) + git -C sass-spec pull --depth=1 git://github.com/sass/sass-spec "$ref" bundle config local.sass-spec "$(pwd)/sass-spec" fi diff --git a/extra/sass-spec-ref.sh b/extra/sass-spec-ref.sh index d487f7aef..8f48e0d1f 100755 --- a/extra/sass-spec-ref.sh +++ b/extra/sass-spec-ref.sh @@ -18,7 +18,15 @@ fi >&2 echo "Fetching pull request $TRAVIS_PULL_REQUEST..." -JSON=$(curl -L -sS https://api.github.com/repos/sass/sass/pulls/$TRAVIS_PULL_REQUEST) +url=https://api.github.com/repos/sass/sass/pulls/$TRAVIS_PULL_REQUEST +if [ -z "$GITHUB_AUTH" ]; then + >&2 echo "Fetching pull request info without authentication" + JSON=$(curl -L -sS $url) +else + >&2 echo "Fetching pull request info as sassbot" + JSON=$(curl -u "sassbot:$GITHUB_AUTH" -L -sS $url) +fi +>&2 echo "$JSON" RE_SPEC_PR="sass\/sass-spec(#|\/pull\/)([0-9]+)" From d7d485e5f19a68734731922f54c124c75bc97328 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 21 Jun 2018 15:01:39 -0400 Subject: [PATCH 4/4] Look for pull requests in the correct repository --- extra/sass-spec-ref.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/sass-spec-ref.sh b/extra/sass-spec-ref.sh index 8f48e0d1f..5e0f885d7 100755 --- a/extra/sass-spec-ref.sh +++ b/extra/sass-spec-ref.sh @@ -18,7 +18,7 @@ fi >&2 echo "Fetching pull request $TRAVIS_PULL_REQUEST..." -url=https://api.github.com/repos/sass/sass/pulls/$TRAVIS_PULL_REQUEST +url=https://api.github.com/repos/sass/ruby-sass/pulls/$TRAVIS_PULL_REQUEST if [ -z "$GITHUB_AUTH" ]; then >&2 echo "Fetching pull request info without authentication" JSON=$(curl -L -sS $url)