Skip to content

Commit 36fc350

Browse files
committed
Fix an addition bug with str-slice
This a forward of #2254 to master which is tracking 3.5
1 parent ff449dc commit 36fc350

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/functions.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,21 @@ namespace Sass {
10161016
String_Constant_Ptr s = ARG("$string", String_Constant);
10171017
double start_at = ARG("$start-at", Number)->value();
10181018
double end_at = ARG("$end-at", Number)->value();
1019+
String_Quoted_Ptr ss = SASS_MEMORY_CAST_PTR(String_Quoted, s);
10191020

10201021
std::string str = unquote(s->value());
10211022

10221023
size_t size = utf8::distance(str.begin(), str.end());
10231024

1024-
if (end_at < size * -1.0 && size > 1) {
1025-
end_at = 0;
1025+
if (!SASS_MEMORY_CAST(Number, env["$end-at"])) {
1026+
end_at = -1;
10261027
}
1028+
1029+
if (end_at == 0 || (end_at + size) < 0) {
1030+
if (ss && ss->quote_mark()) newstr = quote("");
1031+
return SASS_MEMORY_NEW(String_Quoted, pstate, newstr);
1032+
}
1033+
10271034
if (end_at < 0) {
10281035
end_at += size + 1;
10291036
if (end_at == 0) end_at = 1;
@@ -1043,7 +1050,7 @@ namespace Sass {
10431050
utf8::advance(end, end_at - start_at + 1, str.end());
10441051
newstr = std::string(start, end);
10451052
}
1046-
if (String_Quoted_Ptr ss = SASS_MEMORY_CAST_PTR(String_Quoted, s)) {
1053+
if (ss) {
10471054
if(ss->quote_mark()) newstr = quote(newstr);
10481055
}
10491056
}

0 commit comments

Comments
 (0)