Fix regex being too greedy

This commit is contained in:
Frank A. Krueger 2020-03-08 18:33:28 -07:00
parent 266b1a1fa8
commit fe690fd13c
No known key found for this signature in database
GPG Key ID: 0471C67474FFE664
2 changed files with 21 additions and 1 deletions

View File

@ -97,7 +97,7 @@ namespace Ooui
public PublishedPath (string path, RequestHandler handler)
{
Path = path;
RegexPath = new Regex (path);
RegexPath = new Regex ("^" + path + "$");
Handler = handler;
}
}

View File

@ -107,6 +107,26 @@ namespace Tests
Assert.AreEqual ("\"nvirueh4\"", r);
}
[TestMethod]
public void PatternUrlCompleteMatch ()
{
bool gotRequest = false;
UI.PublishJson ("/", x => {
throw new Exception ("Pattern match failed to /");
});
UI.PublishJson ("/patter", x => {
throw new Exception ("Pattern match failed to /patter");
});
UI.PublishJson ("/pattern/(?<id>[a-z0-9]+)", x => {
gotRequest = true;
Assert.AreEqual ("nvirueh4", x["id"]);
return x["id"];
});
var r = DownloadUI ("/pattern/nvirueh4");
Assert.IsTrue (gotRequest);
Assert.AreEqual ("\"nvirueh4\"", r);
}
[TestMethod]
public void PublishEmptyFile ()
{