Skip to content

Commit

Permalink
Fix string.insert with negative indices
Browse files Browse the repository at this point in the history
  • Loading branch information
jathak committed Jan 12, 2022
1 parent 720c358 commit 0d4f420
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
@@ -1,5 +1,7 @@
## 1.47.1

* Fix a bug in `string.insert` with certain negative indices.

### JS API

* **Potentially breaking bug fix:** Match the specification of the new JS API by
Expand All @@ -19,7 +21,7 @@

* **Potentially breaking bug fix:** Match the specification of the new JS API by
passing `undefined` rather than `null` to `Logger.warn()` for an unset `span`.

#### TypeScript Declarations

* Add a declaration for the `LegacyPluginThis.options.context` field.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/functions/string.dart
Expand Up @@ -66,7 +66,7 @@ final _insert = _function("insert", r"$string, $insert, $index", (arguments) {
if (indexInt < 0) {
// +1 because negative indexes start counting from -1 rather than 0, and
// another +1 because we want to insert *after* that index.
indexInt = string.sassLength + indexInt + 2;
indexInt = math.max(string.sassLength + indexInt + 2, 0);
}

var codepointIndex = _codepointForIndex(indexInt, string.sassLength);
Expand Down

0 comments on commit 0d4f420

Please sign in to comment.