diff --git a/akka-http-tests/src/test/scala/akka/http/server/directives/PathDirectivesSpec.scala b/akka-http-tests/src/test/scala/akka/http/server/directives/PathDirectivesSpec.scala index f472af4fd8..a8839adbf8 100644 --- a/akka-http-tests/src/test/scala/akka/http/server/directives/PathDirectivesSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/server/directives/PathDirectivesSpec.scala @@ -94,6 +94,11 @@ class PathDirectivesSpec extends RoutingSpec { "reject [/black]" in test() } + "pathPrefix(Map.empty)" should { + val test = testFor(pathPrefix(Map[String, Int]()) { echoCaptureAndUnmatchedPath }) + "reject [/black]" in test() + } + "pathPrefix(Segment)" should { val test = testFor(pathPrefix(Segment) { echoCaptureAndUnmatchedPath }) "accept [/abc]" in test("abc:") diff --git a/akka-http/src/main/scala/akka/http/server/PathMatcher.scala b/akka-http/src/main/scala/akka/http/server/PathMatcher.scala index fccdc1c54b..354cf8d934 100644 --- a/akka-http/src/main/scala/akka/http/server/PathMatcher.scala +++ b/akka-http/src/main/scala/akka/http/server/PathMatcher.scala @@ -253,7 +253,8 @@ trait ImplicitPathMatcherConstruction { * the matcher consumes this path segment (prefix) and extracts the corresponding map value. */ implicit def valueMap2PathMatcher[T](valueMap: Map[String, T]): PathMatcher1[T] = - valueMap.map { case (prefix, value) ⇒ stringExtractionPair2PathMatcher(prefix, value) }.reduceLeft(_ | _) + if (valueMap.isEmpty) PathMatchers.nothingMatcher + else valueMap.map { case (prefix, value) ⇒ stringExtractionPair2PathMatcher(prefix, value) }.reduceLeft(_ | _) } trait PathMatchers { @@ -435,6 +436,14 @@ trait PathMatchers { * If the path has a trailing slash this slash will *not* be matched. */ def Segments(maxSegments: Int): PathMatcher1[List[String]] = Segment.repeat(maxIterations = maxSegments, separator = Slash) + + /** + * A PathMatcher that never matches anything. + */ + def nothingMatcher[L: Tuple]: PathMatcher[L] = + new PathMatcher[L] { + def apply(p: Path) = Unmatched + } } object PathMatchers extends PathMatchers