Skip to content

Commit 3cc9217

Browse files
committed
Quote version string in replaceAllIn
... so that version ranges are matched literally. closes #26
1 parent 747cf38 commit 3cc9217

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

modules/core/src/main/scala/eu/timepit/scalasteward/github.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object github {
4444
"--data",
4545
s"""{
4646
| "title": "${localUpdate.commitMsg}",
47-
| "body": "Update ${localUpdate.update.groupId}:${localUpdate.update.artifactId} from ${localUpdate.update.currentVersion} to ${localUpdate.update.nextVersion}.",
47+
| "body": "Updates ${localUpdate.update.groupId}:${localUpdate.update.artifactId} from ${localUpdate.update.currentVersion} to ${localUpdate.update.nextVersion}.",
4848
| "head": "$myLogin:${localUpdate.updateBranch.name}",
4949
| "base": "${localUpdate.localRepo.base.name}"
5050
|}

modules/core/src/main/scala/eu/timepit/scalasteward/model/Update.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package eu.timepit.scalasteward.model
1919
import cats.data.NonEmptyList
2020
import cats.implicits._
2121

22+
import scala.util.matching.Regex
23+
2224
final case class Update(
2325
groupId: String,
2426
artifactId: String,
@@ -47,11 +49,12 @@ final case class Update(
4749

4850
def replaceAllIn(str: String): Option[String] = {
4951
def normalize(searchTerm: String): String =
50-
Update
51-
.removeIgnorableSuffix(searchTerm)
52+
Regex
53+
.quoteReplacement(Update.removeIgnorableSuffix(searchTerm))
5254
.replace("-", ".?")
5355

54-
val regex = s"(?i)(${normalize(name)}.*?)$currentVersion".r
56+
val regex =
57+
s"(?i)(${normalize(name)}.*?)${Regex.quote(currentVersion)}".r
5558
var updated = false
5659
val result = regex.replaceAllIn(str, m => {
5760
updated = true

modules/core/src/main/scala/eu/timepit/scalasteward/steward.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ object steward extends IOApp {
161161
(true, s"$pr is behind ${baseBranch.name}")
162162
else
163163
(false, s"$pr is up-to-date with ${baseBranch.name}")
164+
// TODO: Only reset PRs that are still open.
164165
}
165166
_ <- log.printInfo(msg)
166167
} yield result

modules/core/src/test/scala/eu/timepit/scalasteward/model/UpdateTest.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class UpdateTest extends FunSuite with Matchers {
9999
.replaceAllIn(original) shouldBe Some(expected)
100100
}
101101

102+
test("replaceAllIn: version range") {
103+
val original = """Seq("org.specs2" %% "specs2-core" % "3.+" % "test")"""
104+
val expected = """Seq("org.specs2" %% "specs2-core" % "4.3.4" % "test")"""
105+
Update("org.specs2", "specs2-core", "3.+", Nel.of("4.3.4"))
106+
.replaceAllIn(original) shouldBe Some(expected)
107+
}
108+
102109
test("isImpliedBy") {
103110
val update0 = Update("org.specs2", "specs2-core", "3.9.4", Nel.of("3.9.5"))
104111
val update1 = update0.copy(artifactId = "specs2-scalacheck")

0 commit comments

Comments
 (0)