Fixed more bugs in FixHost method.

This commit is contained in:
Dario Solera 2011-01-05 14:19:41 +00:00
parent 9befcf3c13
commit ffa6f12f6b
4 changed files with 23 additions and 8 deletions

View file

@ -16,5 +16,5 @@ using System.Reflection;
// //
// You can specify all the values or you can default the Revision and Build Numbers // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("3.0.4.571")] [assembly: AssemblyVersion("3.0.4.572")]
[assembly: AssemblyFileVersion("3.0.4.571")] [assembly: AssemblyFileVersion("3.0.4.572")]

View file

@ -327,16 +327,31 @@ namespace ScrewTurn.Wiki {
return result; return result;
} }
private static string CleanupPort(string url, string host) {
if(!url.Contains(host)) {
int colonIndex = host.IndexOf(":");
if(colonIndex != -1) {
host = host.Substring(0, colonIndex);
}
}
return host;
}
/// <summary> /// <summary>
/// Automatically replaces the host in the URL with that obtained from <see cref="Settings.GetMainUrl"/>. /// Automatically replaces the host and port in the URL with those obtained from <see cref="Settings.GetMainUrl"/>.
/// </summary> /// </summary>
/// <param name="url">The URL.</param> /// <param name="url">The URL.</param>
/// <returns>The URL with fixed host.</returns> /// <returns>The URL with fixed host and port.</returns>
public static Uri FixHost(this Uri url) { public static Uri FixHost(this Uri url) {
// Make sure the host is replaced only once // Make sure the host is replaced only once
string originalUrl = url.ToString(); string originalUrl = url.ToString();
string originalHost = url.Host; string originalHost = url.GetComponents(UriComponents.HostAndPort, UriFormat.Unescaped);
string newHost = Settings.GetMainUrl().Host; Uri mainUrl = Settings.GetMainUrl();
string newHost = mainUrl.GetComponents(UriComponents.HostAndPort, UriFormat.Unescaped);
originalHost = CleanupPort(originalUrl, originalHost);
newHost = CleanupPort(mainUrl.ToString(), newHost);
int hostIndex = originalUrl.IndexOf(originalHost); int hostIndex = originalUrl.IndexOf(originalHost);
string newUrl = originalUrl.Substring(0, hostIndex) + newHost + originalUrl.Substring(hostIndex + originalHost.Length); string newUrl = originalUrl.Substring(0, hostIndex) + newHost + originalUrl.Substring(hostIndex + originalHost.Length);

View file

@ -45,7 +45,7 @@
<asp:Literal ID="lblWikiUrl" runat="server" Text="Wiki URL" <asp:Literal ID="lblWikiUrl" runat="server" Text="Wiki URL"
EnableViewState="False" meta:resourcekey="lblWikiUrlResource1" /> EnableViewState="False" meta:resourcekey="lblWikiUrlResource1" />
<span class="smalllabel">(<asp:Literal ID="lblUsedForEmailCommunications" <span class="smalllabel">(<asp:Literal ID="lblUsedForEmailCommunications"
runat="server" Text="used for email communications" EnableViewState="False" runat="server" Text="used for email communications and redirects" EnableViewState="False"
meta:resourcekey="lblUsedForEmailCommunicationsResource1" /> - meta:resourcekey="lblUsedForEmailCommunicationsResource1" /> -
<anthem:LinkButton ID="btnAutoWikiUrl" runat="server" Text="autodetect" <anthem:LinkButton ID="btnAutoWikiUrl" runat="server" Text="autodetect"
CausesValidation="False" OnClick="btnAutoWikiUrl_Click" CausesValidation="False" OnClick="btnAutoWikiUrl_Click"

View file

@ -397,7 +397,7 @@
<value /> <value />
</data> </data>
<data name="lblUsedForEmailCommunicationsResource1.Text" xml:space="preserve"> <data name="lblUsedForEmailCommunicationsResource1.Text" xml:space="preserve">
<value>used for email communications</value> <value>used for email communications and redirects</value>
</data> </data>
<data name="lblWikiTitleResource1.Text" xml:space="preserve"> <data name="lblWikiTitleResource1.Text" xml:space="preserve">
<value>Wiki title</value> <value>Wiki title</value>