Fixes sbt/sbt#6496 - bug in version parser

What is the problem?
sbt/sbt#6496 identifies a bug in the logic which assesses whether
different versions of the same transitive dependency are binary
compatible. If one of the transitive dependencies included a version
with a full-stop literal, it would be parsed incorrectly and an error
would be thrown to the user falsely saying that the dependencies are
binary incompatible.

What is the solution?
This PR fixes the regex used by the parser to include full-stop literals.

Is there anything else to be done?
It is worth us checking the rest of the codebase in case this bug might
exist in other parsers. The tests are super helpful for figuring out
which strings might break the current logic.
This commit is contained in:
Amina Adewusi 2021-05-14 19:39:37 +01:00
parent 4c19b9cc7c
commit 6f87212b9f
2 changed files with 8 additions and 1 deletions

View File

@ -66,7 +66,7 @@ object VersionNumber {
def splitDash(s: String) = splitOn(s, '-')
def splitPlus(s: String) = splitOn(s, '+') map ("+" + _)
val TaggedVersion = """(\d{1,14})([\.\d{1,14}]*)((?:-\w+)*)((?:\+.+)*)""".r
val TaggedVersion = """(\d{1,14})([\.\d{1,14}]*)((?:-[\w\.]+)*)((?:\+.+)*)""".r
val NonSpaceString = """(\S+)""".r
s match {

View File

@ -97,6 +97,13 @@ class VersionNumberSpec extends AnyFreeSpec with Matchers with Inside {
assertCascadesTo(v, Seq("0.1.0-MSERVER-1", "0.1.0", "0.1"))
}
version("1.1.0-DLP-7923-presigned-download-url.5") { v =>
assertParsesTo(v, Seq(1, 1, 0), Seq("DLP", "7923", "presigned", "download", "url.5"), Seq())
assertCascadesTo(v, Seq("1.1.0-DLP-7923-presigned-download-url.5", "1.1.0", "1.1"))
assertIsCompatibleWith(v, "1.0.7", EarlySemVer)
assertIsNotCompatibleWith(v, "1.0.7", PackVer)
}
version("2.10.4-20140115-000117-b3a-sources") { v =>
assertParsesTo(v, Seq(2, 10, 4), Seq("20140115", "000117", "b3a", "sources"), Seq())
assertCascadesTo(v, Seq("2.10.4-20140115-000117-b3a-sources", "2.10.4", "2.10"))