Skip to content

Commit 45feae5

Browse files
authored
Merge pull request #3016 from Seetaramayya/fix-StringIndexOutOfBoundsException
Fixed throwing StringIndexOutOfBoundsException
2 parents 1ea3fd8 + 47796a2 commit 45feae5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

modules/core/src/main/scala/org/scalasteward/core/edit/update/data/Substring.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object Substring {
4444
def applyAll(replacements: List[Replacement])(source: String): String = {
4545
var start = 0
4646
val sb = new java.lang.StringBuilder(source.length)
47-
replacements.sortBy(_.position.start).foreach { r =>
47+
replacements.distinctBy(_.position.start).sortBy(_.position.start).foreach { r =>
4848
val before = source.substring(start, r.position.start)
4949
start = r.position.start + r.position.value.length
5050
sb.append(before).append(r.replacement)

modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,17 @@ class RewriteTest extends FunSuite {
431431
runApplyUpdate(update, original, expected)
432432
}
433433

434+
// https://github.com/scala-steward-org/scala-steward/pull/3016
435+
test("artifact change with multiple artifactId cross names") {
436+
val update = ("com.pauldijou".g % Nel.of(
437+
("jwt-core", "jwt-core_2.12").a,
438+
("jwt-core", "jwt-core_2.13").a
439+
) % "5.0.0" %> "9.2.0").single.copy(newerGroupId = Some("com.github.jwt-scala".g))
440+
val original = Map("build.sbt" -> """ "com.pauldijou" %% "jwt-core" % "5.0.0" """)
441+
val expected = Map("build.sbt" -> """ "com.github.jwt-scala" %% "jwt-core" % "9.2.0" """)
442+
runApplyUpdate(update, original, expected)
443+
}
444+
434445
// https://github.com/scala-steward-org/scala-steward/pull/566
435446
test("prevent exception: named capturing group is missing trailing '}'") {
436447
val update =

0 commit comments

Comments
 (0)