From 1c2a2792e3c919fa2c20e6c2e1e33114fde3aa68 Mon Sep 17 00:00:00 2001 From: Alex Leong Date: Thu, 7 Jun 2018 14:08:19 -0700 Subject: [PATCH] Allow underscores in segment capture variable names (#1970) Underscores in match patterns of io.l5d.rewrite do not work. They considered valid characters for match pattern variables in previous Linkerd releases. Update the regex to allow underscores. Fixes #1969 Signed-off-by: Alex Leong --- .../main/scala/com/twitter/finagle/buoyant/PathMatcher.scala | 2 +- .../scala/com/twitter/finagle/buoyant/PathMatcherTest.scala | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/finagle/buoyant/src/main/scala/com/twitter/finagle/buoyant/PathMatcher.scala b/finagle/buoyant/src/main/scala/com/twitter/finagle/buoyant/PathMatcher.scala index 1c89c16799..3d0c229a11 100644 --- a/finagle/buoyant/src/main/scala/com/twitter/finagle/buoyant/PathMatcher.scala +++ b/finagle/buoyant/src/main/scala/com/twitter/finagle/buoyant/PathMatcher.scala @@ -67,7 +67,7 @@ object PathMatcher { override def extract(path: Path): Option[Map[String, String]] = _extract(path.showElems, rawSegments, Map.empty) - private[this] val segmentRegex = """\{([a-zA-Z0-9\.:-]+)\}""".r + private[this] val segmentRegex = """\{([a-zA-Z0-9\.:-_]+)\}""".r private[this] val rawSegments: Seq[MatchSegment] = { expr.split("/").dropWhile(_.isEmpty).map { exprSegment => diff --git a/finagle/buoyant/src/test/scala/com/twitter/finagle/buoyant/PathMatcherTest.scala b/finagle/buoyant/src/test/scala/com/twitter/finagle/buoyant/PathMatcherTest.scala index a11729151d..a6984ffb16 100644 --- a/finagle/buoyant/src/test/scala/com/twitter/finagle/buoyant/PathMatcherTest.scala +++ b/finagle/buoyant/src/test/scala/com/twitter/finagle/buoyant/PathMatcherTest.scala @@ -35,6 +35,11 @@ class PathMatcherTest extends FunSuite { assert(matcher.extract(Path.read("/foo/bar/bas")) == Some(Map("A" -> "bar"))) } + test("capture segment with underscore name") { + val matcher = PathMatcher("/foo/{A_B_C}") + assert(matcher.extract(Path.read("/foo/bar/bas")) == Some(Map("A_B_C" -> "bar"))) + } + test("capture segments with endpoint") { val matcher = PathMatcher("/foo/bar/{A}:http") assert(matcher.extract(Path.read("/foo/bar/bas:http")) == Some(Map("A" -> "bas")))