Repository: scala-steward-org/scala-steward
Pull request #1945 (2021-02-18 22:05:35)

Escape punctuation in UpdateHeuristic.toFlexibleRegex


Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/edit/UpdateHeuristic.scala b/modules/core/src/main/scala/org/scalasteward/core/edit/UpdateHeuristic.scala
index 026628df..3b2cd361 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/edit/UpdateHeuristic.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/edit/UpdateHeuristic.scala
@@ -40,7 +40,7 @@ object UpdateHeuristic {
     */
   private def toFlexibleRegex(string: String): String = {
     val punctuation = List('.', '-', '_')
-    val allowPunctuation = punctuation.mkString("[", "", "]*")
+    val allowPunctuation = "[\\.\\-_]*"
     string.toList
       .collect { case c if !punctuation.contains_(c) => Regex.quote(c.toString) }
       .intercalate(allowPunctuation)
diff --git a/project/Dependencies.scala b/project/Dependencies.scala
index 1010a681..bff85d55 100644
--- a/project/Dependencies.scala
+++ b/project/Dependencies.scala
@@ -8,7 +8,7 @@ object Dependencies {
   val betterFiles = "com.github.pathikrit" %% "better-files" % "3.9.1"
   val betterMonadicFor = "com.olegpy" %% "better-monadic-for" % "0.3.1"
   val caseApp = "com.github.alexarchambault" %% "case-app" % "2.0.4"
-  val catsEffect = "org.typelevel" %% "cats-effect" % "2.3.3"
+  val catsEffect = "org.typelevel" %% "cats-effect" % "2.3.1"
   val catsCore = "org.typelevel" %% "cats-core" % "2.4.2"
   val catsLaws = "org.typelevel" %% "cats-laws" % catsCore.revision
   val circeConfig = "io.circe" %% "circe-config" % "0.8.0"
@@ -22,7 +22,7 @@ object Dependencies {
   val coursierCatsInterop = "io.get-coursier" %% "coursier-cats-interop" % coursierCore.revision
   val cron4sCore = "com.github.alonsodomin.cron4s" %% "cron4s-core" % "0.6.1"
   val disciplineMunit = "org.typelevel" %% "discipline-munit" % "1.0.6"
-  val fs2Core = "co.fs2" %% "fs2-core" % "2.5.2"
+  val fs2Core = "co.fs2" %% "fs2-core" % "2.5.0"
   val fs2Io = "co.fs2" %% "fs2-io" % fs2Core.revision
   val http4sCore = "org.http4s" %% "http4s-core" % "0.21.19"
   val http4sCirce = "org.http4s" %% "http4s-circe" % http4sCore.revision
@@ -40,7 +40,7 @@ object Dependencies {
   val monocleCore = "com.github.julien-truffaut" %% "monocle-core" % "2.1.0"
   val munit = "org.scalameta" %% "munit" % "0.7.22"
   val munitScalacheck = "org.scalameta" %% "munit-scalacheck" % munit.revision
-  val refined = "eu.timepit" %% "refined" % "0.9.21"
+  val refined = "eu.timepit" %% "refined" % "0.9.20"
   val refinedCats = "eu.timepit" %% "refined-cats" % refined.revision
   val refinedScalacheck = "eu.timepit" %% "refined-scalacheck" % refined.revision
   val scalacacheCaffeine = "com.github.cb372" %% "scalacache-caffeine" % "0.28.0"


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/edit/UpdateHeuristicTest.scala b/modules/core/src/test/scala/org/scalasteward/core/edit/UpdateHeuristicTest.scala
index 24d90205..4ca4dc83 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/edit/UpdateHeuristicTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/edit/UpdateHeuristicTest.scala
@@ -71,11 +71,8 @@ class UpdateHeuristicTest extends FunSuite {
   test("with single quotes around val") {
     val original = """val `scalajs-jquery-version` = "0.9.3""""
     val expected = """val `scalajs-jquery-version` = "0.9.4""""
-    assertEquals(
-      Single("be.doeraene" % "scalajs-jquery" % "0.9.3", Nel.of("0.9.4"))
-        .replaceVersionIn(original),
-      Some(expected) -> UpdateHeuristic.relaxed.name
-    )
+    val update = Single("be.doeraene" % "scalajs-jquery" % "0.9.3", Nel.of("0.9.4"))
+    assertEquals(update.replaceVersionIn(original), Some(expected) -> UpdateHeuristic.original.name)
   }
 
   test("all upper case") {
@@ -658,6 +655,17 @@ class UpdateHeuristicTest extends FunSuite {
       Some(expected) -> UpdateHeuristic.original.name
     )
   }
+
+  test("chars of search term contained in other term") {
+    val original = """val cats = "2.4.1"
+                     |val scalaReactJsTestState = "2.4.1"
+                     |""".stripMargin
+    val expected = """val cats = "2.4.2"
+                     |val scalaReactJsTestState = "2.4.1"
+                     |""".stripMargin
+    val update = Single("org.typelevel" % "cats-core" % "2.4.1", Nel.of("2.4.2"))
+    assertEquals(update.replaceVersionIn(original), Some(expected) -> UpdateHeuristic.original.name)
+  }
 }
 
 object UpdateHeuristicTest {