From aa217cf90fbecf9334fc60d588968723ed17c351 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Wed, 2 Apr 2014 08:52:44 +0300 Subject: [PATCH] Better string matching when searching for REST handlers: must match an entire path component (ending with '/' or a similar character). For example, these should match: "/assets" and "/assets/12345", but these shouldn't match: "/assets" and "/assets_exist". --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 7041181613..e4a244e26a 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -857,6 +857,8 @@ namespace OpenSim.Framework.Servers.HttpServer } } + private readonly string HANDLER_SEPARATORS = "/?&#"; + private bool TryGetStreamHandler(string handlerKey, out IRequestHandler streamHandler) { string bestMatch = null; @@ -865,7 +867,8 @@ namespace OpenSim.Framework.Servers.HttpServer { foreach (string pattern in m_streamHandlers.Keys) { - if (handlerKey.StartsWith(pattern)) + if ((handlerKey == pattern) + || (handlerKey.StartsWith(pattern) && (HANDLER_SEPARATORS.IndexOf(handlerKey[pattern.Length]) >= 0))) { if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length) { @@ -895,7 +898,8 @@ namespace OpenSim.Framework.Servers.HttpServer { foreach (string pattern in m_pollHandlers.Keys) { - if (handlerKey.StartsWith(pattern)) + if ((handlerKey == pattern) + || (handlerKey.StartsWith(pattern) && (HANDLER_SEPARATORS.IndexOf(handlerKey[pattern.Length]) >= 0))) { if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length) { @@ -927,7 +931,8 @@ namespace OpenSim.Framework.Servers.HttpServer { foreach (string pattern in m_HTTPHandlers.Keys) { - if (handlerKey.StartsWith(pattern)) + if ((handlerKey == pattern) + || (handlerKey.StartsWith(pattern) && (HANDLER_SEPARATORS.IndexOf(handlerKey[pattern.Length]) >= 0))) { if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length) {