optimize UrlCombine method
This commit is contained in:
parent
543f4fa3c2
commit
575bbdb53b
@ -1,8 +1,6 @@
|
||||
using Oqtane.Models;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@ -390,14 +388,19 @@ namespace Oqtane.Shared
|
||||
|
||||
public static string UrlCombine(params string[] segments)
|
||||
{
|
||||
segments = segments.Where(item => !string.IsNullOrEmpty(item) && item != "/" && item != "\\").ToArray();
|
||||
var url = new List<string>();
|
||||
for (int i = 0; i < segments.Length; i++)
|
||||
{
|
||||
segments[i] = (segments[i].StartsWith("/") || segments[i].StartsWith("\\")) ? segments[i].Substring(1) : segments[i];
|
||||
segments[i] = (segments[i].EndsWith("/") || segments[i].EndsWith("\\")) ? segments[i].Substring(0, segments[i].Length - 1) : segments[i];
|
||||
{
|
||||
segments[i] = segments[i].Replace("\\", "/");
|
||||
if (!string.IsNullOrEmpty(segments[i]) && segments[i] != "/")
|
||||
{
|
||||
foreach (var segment in segments[i].Split('/', StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
url.Add(segment);
|
||||
}
|
||||
}
|
||||
}
|
||||
return string.Join("/", segments);
|
||||
return string.Join("/", url);
|
||||
}
|
||||
|
||||
public static bool IsPathValid(this Folder folder)
|
||||
|
Reference in New Issue
Block a user