summaryrefslogtreecommitdiff
path: root/scss
diff options
context:
space:
mode:
authorWilliam Anderson <william@thewilliamanderson.com>2015-08-04 10:25:04 -0400
committerWilliam Anderson <william@thewilliamanderson.com>2015-08-04 10:25:04 -0400
commitd15319c89fc41b62131a382ecb3497959b6c56c1 (patch)
treef4341725985c9eb8c3d3256c1592703f3a58bae5 /scss
parentb1621dca6b554d793f01eee7831997ae477ca7ec (diff)
downloadpyscss-d15319c89fc41b62131a382ecb3497959b6c56c1.tar.gz
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.
Diffstat (limited to 'scss')
-rw-r--r--scss/extension/core.py8
1 files changed, 6 insertions, 2 deletions
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)