From 3dabc4839e488cab08e55f55345640f48e35c554 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Sat, 2 Nov 2019 14:48:44 +0100 Subject: [PATCH] Add function to combine web Urls properly --- lib/core/tools/Join-WebPath.psm1 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/core/tools/Join-WebPath.psm1 diff --git a/lib/core/tools/Join-WebPath.psm1 b/lib/core/tools/Join-WebPath.psm1 new file mode 100644 index 0000000..8a91545 --- /dev/null +++ b/lib/core/tools/Join-WebPath.psm1 @@ -0,0 +1,24 @@ +function Join-WebPath() +{ + param( + [string]$Path, + [string]$ChildPath + ); + + if ([string]::IsNullOrEmpty($Path) -Or [string]::IsNullOrEmpty($ChildPath)) { + return $Path; + } + + [int]$Length = $Path.Length; + [int]$Slash = $Path.LastIndexOf('/') + 1; + + if ($Length -eq $Slash) { + $Path = $Path.Substring(0, $Path.Length - 1); + } + + if ($ChildPath[0] -eq '/') { + return ([string]::Format('{0}{1}', $Path, $ChildPath)); + } + + return ([string]::Format('{0}/{1}', $Path, $ChildPath)); +}