From 7ae6910853d270a8e215db2d92dc7395bfc918a2 Mon Sep 17 00:00:00 2001 From: high Date: Mon, 5 Sep 2011 15:06:08 -0400 Subject: [PATCH] Endpoint registering '/ep' will no longer match '/ep/x'. Trailing slashes removed. So '/ep/' will become '/ep'. --- TShockAPI/Rest/Rest.cs | 7 +++++-- TShockAPI/Rest/RestCommand.cs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Rest/Rest.cs b/TShockAPI/Rest/Rest.cs index aa668f01..d27873ad 100644 --- a/TShockAPI/Rest/Rest.cs +++ b/TShockAPI/Rest/Rest.cs @@ -79,12 +79,15 @@ namespace Rests protected virtual object ProcessRequest(object sender, RequestEventArgs e) { + var uri = e.Request.Uri.AbsolutePath; + uri = uri.TrimEnd('/'); + foreach (var com in commands) { var verbs = new RestVerbs(); if (com.HasVerbs) { - var match = Regex.Match(e.Request.Uri.AbsolutePath, com.UriVerbMatch); + var match = Regex.Match(uri, com.UriVerbMatch); if (!match.Success) continue; if ((match.Groups.Count - 1) != com.UriVerbs.Length) @@ -93,7 +96,7 @@ namespace Rests for (int i = 0; i < com.UriVerbs.Length; i++) verbs.Add(com.UriVerbs[i], match.Groups[i + 1].Value); } - else if (com.UriTemplate.ToLower() != e.Request.Uri.AbsolutePath.ToLower()) + else if (com.UriTemplate.ToLower() != uri.ToLower()) { continue; } diff --git a/TShockAPI/Rest/RestCommand.cs b/TShockAPI/Rest/RestCommand.cs index b5bd37f2..82ca22b1 100644 --- a/TShockAPI/Rest/RestCommand.cs +++ b/TShockAPI/Rest/RestCommand.cs @@ -22,7 +22,7 @@ namespace Rests { Name = name; UriTemplate = uritemplate; - UriVerbMatch = string.Join("([^/]*)", Regex.Split(uritemplate, "\\{[^\\{\\}]*\\}")); + UriVerbMatch = string.Format("^{0}$", string.Join("([^/]*)", Regex.Split(uritemplate, "\\{[^\\{\\}]*\\}"))); var matches = Regex.Matches(uritemplate, "\\{([^\\{\\}]*)\\}"); UriVerbs = (from Match match in matches select match.Groups[1].Value).ToArray(); Callback = callback;