Skip to content

Commit

Permalink
Fixes Issue kipusoep#177 and prevents double slashes at the start of …
Browse files Browse the repository at this point in the history
…a path when redirecting to an absolute url
  • Loading branch information
ProNotion committed Dec 19, 2017
1 parent 0ca9a5f commit c5289ec
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Modules/UrlTrackerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,15 @@ static void UrlTrackerDo(string callingEventName, bool ignoreHttpStatusCode = fa
NameValueCollection newQueryString = HttpUtility.ParseQueryString(request.Url.Query);
if (redirectQueryString.HasKeys())
newQueryString = newQueryString.Merge(redirectQueryString);
string pathAndQuery = Uri.UnescapeDataString(redirectUri.PathAndQuery) + redirectUri.Fragment;
redirectUri = new Uri(string.Format("{0}{1}{2}{3}/{4}{5}", redirectUri.Scheme, Uri.SchemeDelimiter, redirectUri.Host, redirectUri.Port != 80 && UrlTrackerSettings.AppendPortNumber ? string.Concat(":", redirectUri.Port) : string.Empty, pathAndQuery.Contains('?') ? pathAndQuery.Substring(0, pathAndQuery.IndexOf('?')) : pathAndQuery.StartsWith("/") ? pathAndQuery.Substring(1) : pathAndQuery, newQueryString.HasKeys() ? string.Concat("?", newQueryString.ToQueryString()) : string.Empty));
string pathAndQuery = Uri.UnescapeDataString(redirectUri.PathAndQuery.EnsureStartsWith("/")) + redirectUri.Fragment;
// Determine if we need to include the port number
string port = redirectUri.Port != 80 && UrlTrackerSettings.AppendPortNumber ? string.Concat(":", redirectUri.Port) : string.Empty;
// Extract the Uri path wihtout any querystring
string path = pathAndQuery.Contains('?') ? pathAndQuery.Substring(0, pathAndQuery.IndexOf('?')) : pathAndQuery.StartsWith("/") ? pathAndQuery.Substring(1) : pathAndQuery;
// Assemble the new querystring but only if there are key/values to pass through
string querystring = newQueryString.HasKeys() ? string.Concat("?", newQueryString.ToQueryString()) : string.Empty;

redirectUri = new Uri(string.Format("{0}{1}{2}{3}{4}{5}", redirectUri.Scheme, Uri.SchemeDelimiter, redirectUri.Host, port, path, querystring));
}

if (redirectUri == new Uri(string.Format("{0}{1}{2}{3}/{4}", request.Url.Scheme, Uri.SchemeDelimiter, request.Url.Host, request.Url.Port != 80 && UrlTrackerSettings.AppendPortNumber ? string.Concat(":", request.Url.Port) : string.Empty, request.RawUrl.StartsWith("/") ? request.RawUrl.Substring(1) : request.RawUrl)))
Expand Down

0 comments on commit c5289ec

Please sign in to comment.