Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
[BugFix] Not allowed root "/" in old url ([#79](#79))
Browse files Browse the repository at this point in the history
  • Loading branch information
kipusoep committed May 26, 2015
1 parent 592312e commit 2fad9b7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 36 deletions.
72 changes: 38 additions & 34 deletions Helpers/UrlTrackerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,49 @@

namespace InfoCaster.Umbraco.UrlTracker.Helpers
{
public static class UrlTrackerHelper
{
static readonly Regex _urlWithDotRegex = new Regex("\\S+\\.\\S+");
public static class UrlTrackerHelper
{
static readonly Regex _urlWithDotRegex = new Regex("\\S+\\.\\S+");

public static string ResolveShortestUrl(string url)
{
if (url.StartsWith("http://") || url.StartsWith("https://"))
{
public static string ResolveShortestUrl(string url)
{
if (url.StartsWith("http://") || url.StartsWith("https://"))
{
Uri uri = new Uri(url);
url = Uri.UnescapeDataString(uri.PathAndQuery);
}
// The URL should be stored as short as possible (e.g.: /page.aspx -> page | /page/ -> page)
if (url.StartsWith("/"))
url = url.Substring(1);
if (url.EndsWith("/"))
url = url.Substring(0, url.Length - "/".Length);
if (url.EndsWith(".aspx"))
url = url.Substring(0, url.Length - ".aspx".Length);
url = Uri.UnescapeDataString(uri.PathAndQuery);
}

if (url != "/")
{
// The URL should be stored as short as possible (e.g.: /page.aspx -> page | /page/ -> page)
if (url.StartsWith("/"))
url = url.Substring(1);
if (url.EndsWith("/"))
url = url.Substring(0, url.Length - "/".Length);
if (url.EndsWith(".aspx"))
url = url.Substring(0, url.Length - ".aspx".Length);
}
return url;
}
}

public static string ResolveUmbracoUrl(string url)
{
if (url.StartsWith("http://") || url.StartsWith("https://"))
{
Uri uri = new Uri(url);
url = Uri.UnescapeDataString(uri.PathAndQuery);
}
public static string ResolveUmbracoUrl(string url)
{
if (url.StartsWith("http://") || url.StartsWith("https://"))
{
Uri uri = new Uri(url);
url = Uri.UnescapeDataString(uri.PathAndQuery);
}

if (url != "/" && !_urlWithDotRegex.IsMatch(url))
{
if (!GlobalSettings.UseDirectoryUrls && !url.EndsWith(".aspx"))
url += ".aspx";
else if (UmbracoSettings.AddTrailingSlash && !url.EndsWith("/"))
url += "/";
}
if (url != "/" && !_urlWithDotRegex.IsMatch(url))
{
if (!GlobalSettings.UseDirectoryUrls && !url.EndsWith(".aspx"))
url += ".aspx";
else if (UmbracoSettings.AddTrailingSlash && !url.EndsWith("/"))
url += "/";
}

return url;
}
return url;
}

public static string GetName(UrlTrackerDomain domain)
{
Expand All @@ -64,5 +68,5 @@ public static string GetName(UrlTrackerDomain domain)
return string.Format("{0} ({1})", domain.Node.Name, domain.Name);
}
}
}
}
}
2 changes: 1 addition & 1 deletion Modules/UrlTrackerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static void UrlTrackerDo(string callingEventName, bool ignoreHttpStatusCode = fa
}

string url = request.RawUrl;
if (url.StartsWith("/"))
if (url.StartsWith("/") && url != "/")
url = url.Substring(1);

LoggingHelper.LogInformation("UrlTracker HttpModule | Incoming URL is: {0}", url);
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("3.8.*")]
[assembly: AssemblyVersion("3.9.*")]

// SQL
[assembly: WebResource("InfoCaster.Umbraco.UrlTracker.SQL.MicrosoftSqlServer.create-table-1.sql", "text/plain")]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Set to true to disable tracking not found (404) requests.
Set to false to disable appending a port number to redirect URLs

## Changelog ##
* 3.9 [2015/05/26]
* [BugFix] Not allowed root "/" in old url ([#79](https://github.com/kipusoep/UrlTracker/issues/79))
* 3.8 [2015/05/22]
* [BugFix] Redirects were not working in some cases, for example ([Not working - it returns 404](https://our.umbraco.org/projects/developer-tools/301-url-tracker/version-2/64883-Not-working-it-returns-404))
* [Improvement] Performance improvement; no SQL queries will be performed anymore for valid requests :-)
Expand Down
6 changes: 6 additions & 0 deletions UI/UrlTrackerInfo.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
</div>
<div class="tab-pane" id="changeLog">
<ul>
<li>
3.9 [2015/05/26]
<ul>
<li>[BugFix] Not allowed root "/" in old url <a target="_blank" href="https://github.com/kipusoep/UrlTracker/issues/79">#79</a></li>
</ul>
</li>
<li>
3.8 [2015/05/22]
<ul>
Expand Down

0 comments on commit 2fad9b7

Please sign in to comment.