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".
0.8.0.3
Oren Hurvitz 2014-04-02 08:52:44 +03:00
parent bbfda8e19e
commit aa217cf90f
1 changed files with 8 additions and 3 deletions

View File

@ -857,6 +857,8 @@ namespace OpenSim.Framework.Servers.HttpServer
} }
} }
private readonly string HANDLER_SEPARATORS = "/?&#";
private bool TryGetStreamHandler(string handlerKey, out IRequestHandler streamHandler) private bool TryGetStreamHandler(string handlerKey, out IRequestHandler streamHandler)
{ {
string bestMatch = null; string bestMatch = null;
@ -865,7 +867,8 @@ namespace OpenSim.Framework.Servers.HttpServer
{ {
foreach (string pattern in m_streamHandlers.Keys) 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) if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length)
{ {
@ -895,7 +898,8 @@ namespace OpenSim.Framework.Servers.HttpServer
{ {
foreach (string pattern in m_pollHandlers.Keys) 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) if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length)
{ {
@ -927,7 +931,8 @@ namespace OpenSim.Framework.Servers.HttpServer
{ {
foreach (string pattern in m_HTTPHandlers.Keys) 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) if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length)
{ {