From 7459d197558e1a5fe29c6e8790f6297b1de6b13d Mon Sep 17 00:00:00 2001 From: xzyfer Date: Thu, 26 Jul 2018 19:50:08 +1000 Subject: [PATCH] Support hex colors with alpha channels A deprecation for the old behaviour landed in #2302. This PR removes the deprecation warning for the old behaviour, and starts parsing 4 and 8 digit hex values as Colors. Looks like we had support for 8 digit hex colors for a while but somehow 4 digit support was missed. Spec https://github.com/sass/sass-spec/pull/1273 Fixes #2674 --- src/parser.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/parser.cpp b/src/parser.cpp index 2933ec708e..28fe02244e 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1598,6 +1598,19 @@ namespace Sass { 1, // alpha channel parsed); } + else if (parsed.length() == 5) { + std::string r(2, parsed[1]); + std::string g(2, parsed[2]); + std::string b(2, parsed[3]); + std::string a(2, parsed[4]); + color = SASS_MEMORY_NEW(Color, + pstate, + static_cast(strtol(r.c_str(), NULL, 16)), + static_cast(strtol(g.c_str(), NULL, 16)), + static_cast(strtol(b.c_str(), NULL, 16)), + static_cast(strtol(a.c_str(), NULL, 16)) / 255, + parsed); + } else if (parsed.length() == 7) { std::string r(parsed.substr(1,2)); std::string g(parsed.substr(3,2)); @@ -1694,17 +1707,7 @@ namespace Sass { { return lexed_hex_color(lexed); } if (lex< hexa >()) - { - std::string s = lexed.to_string(); - - deprecated( - "The value \""+s+"\" is currently parsed as a string, but it will be parsed as a color in", - "future versions of Sass. Use \"unquote('"+s+"')\" to continue parsing it as a string.", - true, pstate - ); - - return SASS_MEMORY_NEW(String_Quoted, pstate, lexed); - } + { return lexed_hex_color(lexed); } if (lex< sequence < exactly <'#'>, identifier > >()) { return SASS_MEMORY_NEW(String_Quoted, pstate, lexed); }