mirror of
https://github.com/danog/dart-sass.git
synced 2024-11-27 04:34:59 +01:00
Fix str-insert() with negative indices. (#85)
This commit is contained in:
parent
a212999554
commit
bf464f0539
@ -1,5 +1,7 @@
|
||||
## 1.0.0-alpha.7
|
||||
|
||||
* `str-index()` now correctly inserts at negative indices.
|
||||
|
||||
* Properly parse `url()`s that contain comment-like text.
|
||||
|
||||
* Fix a few more small `@extend` bugs.
|
||||
|
@ -491,9 +491,24 @@ void defineCoreFunctions(Environment environment) {
|
||||
var index = arguments[2].assertNumber("index");
|
||||
index.assertNoUnits("index");
|
||||
|
||||
var codeUnitIndex = codepointIndexToCodeUnitIndex(string.text,
|
||||
_codepointForIndex(index.assertInt("index"), string.text.runes.length));
|
||||
var indexInt = index.assertInt("index");
|
||||
var codepointIndex = _codepointForIndex(indexInt, string.text.runes.length,
|
||||
allowNegative: true);
|
||||
|
||||
// str-insert has unusual behavior for negative inputs. It guarantees that
|
||||
// the $insert is at $index in the result, which means that we want to
|
||||
// insert before that point if $index is positive and after if it's
|
||||
// negative.
|
||||
if (indexInt < 0) {
|
||||
if (codepointIndex < 0) {
|
||||
codepointIndex = 0;
|
||||
} else {
|
||||
codepointIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
var codeUnitIndex =
|
||||
codepointIndexToCodeUnitIndex(string.text, codepointIndex);
|
||||
return new SassString(
|
||||
string.text.replaceRange(codeUnitIndex, codeUnitIndex, insert.text),
|
||||
quotes: string.hasQuotes);
|
||||
|
Loading…
Reference in New Issue
Block a user