Skip to content

Commit 93eaf22

Browse files
authored
- Fix nested url issue with API Object. 105225 (#1005)
* - Fix nested url issue with API Object. 105225 * - Old case was failing tests. 105225
1 parent c7d684f commit 93eaf22

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,19 +351,49 @@ internal string GetGxRouteValue(string path)
351351
}
352352
public bool ServiceInPath(String path, out String actualPath)
353353
{
354-
actualPath = string.Empty;
355-
foreach (String subPath in servicesPathUrl.Keys)
354+
string tmppath = path.Substring(0, 1).Equals("/") ? path.Substring(1) : path;
355+
int pos = tmppath.IndexOf("/");
356+
string innerPath = tmppath.Substring(pos, tmppath.Length - pos);
357+
actualPath = FindPath( innerPath, servicesPathUrl, true);
358+
if (String.IsNullOrEmpty(actualPath))
356359
{
357-
if (path.ToLower().Contains($"/{subPath.ToLower()}"))
360+
// fallback
361+
actualPath = FindPath(path, servicesPathUrl, false);
362+
if (String.IsNullOrEmpty(actualPath))
363+
{
364+
actualPath = String.Empty;
365+
GXLogging.Debug(log, $"ServiceInPath path:{path} not found");
366+
return false;
367+
}
368+
else
369+
{
370+
return true;
371+
}
372+
}
373+
else {
374+
return true;
375+
}
376+
}
377+
378+
private String FindPath(string innerPath, Dictionary<string,string > servicesPathUrl, bool startTxt)
379+
{
380+
string actualPath = String.Empty;
381+
foreach (var subPath in from String subPath in servicesPathUrl.Keys
382+
select subPath)
383+
{
384+
bool match = false;
385+
innerPath = innerPath.ToLower();
386+
match = (startTxt)? innerPath.StartsWith($"/{subPath.ToLower()}"): innerPath.Contains($"/{subPath.ToLower()}");
387+
if (match)
358388
{
359389
actualPath = subPath.ToLower();
360390
GXLogging.Debug(log, $"ServiceInPath actualPath:{actualPath}");
361-
return true;
391+
return subPath;
362392
}
363393
}
364-
GXLogging.Debug(log, $"ServiceInPath path:{path} not found");
365-
return false;
394+
return null;
366395
}
396+
367397
public GxRestWrapper GetController(HttpContext context, string controller, string methodName, Dictionary<string, string> variableAlias)
368398
{
369399
return GetController(context, new ControllerInfo() { Name = controller, MethodName = methodName, VariableAlias = variableAlias });

0 commit comments

Comments
 (0)