From d15319c89fc41b62131a382ecb3497959b6c56c1 Mon Sep 17 00:00:00 2001 From: William Anderson Date: Tue, 4 Aug 2015 10:25:04 -0400 Subject: Increases parity of str-slice with Sass str-slice relates to issue #338 When using str-slice the compiler should correct for out of bounds or index zero, like ruby Sass. This is also essential for use with the Bourbon library as of 4.2.3 and its implementation of is-length, which is handled perfectly fine by Ruby Sass. --- scss/extension/core.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'scss') diff --git a/scss/extension/core.py b/scss/extension/core.py index 6642f1d..c1bdd53 100644 --- a/scss/extension/core.py +++ b/scss/extension/core.py @@ -576,9 +576,13 @@ def str_index(string, substring): def str_slice(string, start_at, end_at=None): expect_type(string, String) expect_type(start_at, Number, unit=None) - py_start_at = start_at.to_python_index(len(string.value)) - if end_at is None: + if int(start_at) == 0: + py_start_at = 1 + else: + py_start_at = start_at.to_python_index(len(string.value)) + + if end_at is None or int(end_at) > len(string): py_end_at = None else: expect_type(end_at, Number, unit=None) -- cgit v1.2.1