Skip to content

Commit

Permalink
Improve JavaUUID path matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippus committed Jul 23, 2019
1 parent 99e48b6 commit bb556d8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ 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:")
"reject [/]" inThe test()
"reject [/abc]" inThe test()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,8 @@ trait PathMatchers {
* @group pathmatcher
*/
val JavaUUID: PathMatcher1[UUID] =
PathMatcher("""[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}""".r) flatMap { string =>
try Some(UUID.fromString(string))
catch { case _: IllegalArgumentException => None }
}
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)
.map(UUID.fromString)

/**
* A PathMatcher that always matches, doesn't consume anything and extracts nothing.
Expand Down

0 comments on commit bb556d8

Please sign in to comment.