Skip to content

Commit

Permalink
Widen JavaUUID regexp's (#2624)
Browse files Browse the repository at this point in the history
Widen JavaUUID regexp's
  • Loading branch information
jrudolph committed Aug 1, 2019
2 parents 4bc31d5 + 223b0bc commit 2361b16
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ class PathDirectivesSpec extends RoutingSpec with Inside {
val test = testFor(pathPrefix(JavaUUID) { echoCaptureAndUnmatchedPath })
"accept [/bdea8652-f26c-40ca-8157-0b96a2a8389d]" inThe test("bdea8652-f26c-40ca-8157-0b96a2a8389d:")
"accept [/bdea8652-f26c-40ca-8157-0b96a2a8389dyes]" inThe test("bdea8652-f26c-40ca-8157-0b96a2a8389d:yes")
"accept [/00000000-0000-0000-0000-000000000000]" inThe test("00000000-0000-0000-0000-000000000000:")
"accept [/00000000-0000-0000-0000-000000000000]" inThe test("00000000-0000-0000-0000-000000000000:") // nil uuid
"accept [/733a018b-5f16-4699-0e1a-1d3f6f0d0315]" inThe test("733a018b-5f16-4699-0e1a-1d3f6f0d0315:") // variant 0
"accept [/733a018b-5f16-4699-fe1a-1d3f6f0d0315]" inThe test("733a018b-5f16-4699-fe1a-1d3f6f0d0315:") // future variant
"reject [/]" inThe test()
"reject [/abc]" inThe test()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class UnmarshallingSpec extends FreeSpec with Matchers with BeforeAndAfterAll wi
val uuid = UUID.randomUUID()
Unmarshal(uuid.toString).to[UUID] should evaluateTo(uuid)
}
"uuidUnmarshaller should unmarshal variant 0 uuid" in {
val uuid = UUID.fromString("733a018b-5f16-4699-0e1a-1d3f6f0d0315")
Unmarshal(uuid.toString).to[UUID] should evaluateTo(uuid)
}
"uuidUnmarshaller should unmarshal future variant uuid" in {
val uuid = UUID.fromString("733a018b-5f16-4699-fe1a-1d3f6f0d0315")
Unmarshal(uuid.toString).to[UUID] should evaluateTo(uuid)
}
"uuidUnmarshaller should unmarshal nil uuid" in {
Unmarshal("00000000-0000-0000-0000-000000000000").to[UUID] should evaluateTo(UUID.fromString("00000000-0000-0000-0000-000000000000"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ trait PathMatchers {
* @group pathmatcher
*/
val JavaUUID: PathMatcher1[UUID] =
PathMatcher("""[\da-fA-F]{8}-[\da-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][\da-fA-F]{3}-[\da-fA-F]{12}|00000000-0000-0000-0000-000000000000""".r)
PathMatcher("""[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}""".r)
.map(UUID.fromString)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ trait PredefinedFromStringUnmarshallers {

implicit val uuidFromStringUnmarshaller: Unmarshaller[String, UUID] = {
val validUuidPattern =
"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000".r.pattern
"""[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}""".r.pattern

Unmarshaller.strict[String, UUID] { string =>
if (validUuidPattern.matcher(string).matches)
Expand Down

0 comments on commit 2361b16

Please sign in to comment.