Skip to content

Commit

Permalink
Allow underscores in segment capture variable names (linkerd#1970)
Browse files Browse the repository at this point in the history
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 linkerd#1969

Signed-off-by: Alex Leong <alex@buoyant.io>
  • Loading branch information
adleong committed Jun 7, 2018
1 parent 7df8692 commit 1c2a279
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down

0 comments on commit 1c2a279

Please sign in to comment.