diff options
author | William Anderson <william@thewilliamanderson.com> | 2015-08-04 10:25:04 -0400 |
---|---|---|
committer | William Anderson <william@thewilliamanderson.com> | 2015-08-04 10:25:04 -0400 |
commit | d15319c89fc41b62131a382ecb3497959b6c56c1 (patch) | |
tree | f4341725985c9eb8c3d3256c1592703f3a58bae5 /scss | |
parent | b1621dca6b554d793f01eee7831997ae477ca7ec (diff) | |
download | pyscss-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.py | 8 |
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) |