From 4e1b46a958c2d363119c69a90810168055119a52 Mon Sep 17 00:00:00 2001 From: Jennifer Thakar Date: Wed, 12 Jan 2022 14:28:14 -0800 Subject: [PATCH] Fix string.insert with negative indices --- CHANGELOG.md | 6 +++++- lib/src/functions/string.dart | 2 +- pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca3268343..ded183b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.48.1 + +* Fix a bug in `string.insert` with certain negative indices. + ## 1.48.0 ### JS API @@ -23,7 +27,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. diff --git a/lib/src/functions/string.dart b/lib/src/functions/string.dart index ba33bc402..04a441e95 100644 --- a/lib/src/functions/string.dart +++ b/lib/src/functions/string.dart @@ -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); diff --git a/pubspec.yaml b/pubspec.yaml index d82e7d9d0..4e83b80a6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.48.0 +version: 1.48.1-dev description: A Sass implementation in Dart. homepage: https://github.com/sass/dart-sass