Fix str-slice() again.

This commit is contained in:
Natalie Weizenbaum 2017-01-14 22:39:28 -08:00
parent 566c06df0e
commit ca4d411362
3 changed files with 11 additions and 3 deletions

View File

@ -33,6 +33,8 @@
* Properly handle a placeholder selector that isn't at the beginning of a
compound selector.
* Fix more `str-slice()` bugs.
## 1.0.0-alpha.8
* Add the `content-exists()` function.

View File

@ -534,10 +534,16 @@ void defineCoreFunctions(Environment environment) {
end.assertNoUnits("end");
var lengthInCodepoints = string.text.runes.length;
// No matter what the start index is, an end index of 0 will produce an
// empty string.
var endInt = end.assertInt();
if (endInt == 0) return new SassString.empty(quotes: string.hasQuotes);
var startCodepoint =
_codepointForIndex(start.assertInt(), lengthInCodepoints);
var endCodepoint = _codepointForIndex(end.assertInt(), lengthInCodepoints,
allowNegative: true);
var endCodepoint =
_codepointForIndex(endInt, lengthInCodepoints, allowNegative: true);
if (endCodepoint == lengthInCodepoints) endCodepoint -= 1;
if (endCodepoint < startCodepoint) {
return new SassString.empty(quotes: string.hasQuotes);

View File

@ -12,7 +12,7 @@ import '../value.dart';
final _emptyQuoted = new SassString("", quotes: true);
/// An unquoted empty string, returned by [SassString.empty].
final _emptyUnquoted = new SassString("", quotes: true);
final _emptyUnquoted = new SassString("", quotes: false);
/// A SassScript string.
///