Skip to content

Commit

Permalink
Fixed: excluded paths, forcing https while https is on
Browse files Browse the repository at this point in the history
  • Loading branch information
ReoKzK committed Feb 20, 2017
1 parent 9edc614 commit 9a97e48
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 11 deletions.
23 changes: 23 additions & 0 deletions Sitecore.SharedSource.DynamicSitemap.Tests/ExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using Sitecore.SharedSource.DynamicSitemap.Extensions;
using System;

namespace Sitecore.SharedSource.DynamicSitemap.Tests
{
[TestFixture]
public class ExtensionsTests
{
[Test]
public void TestReplaceFirst()
{
String url = "http://old.host.dev/page?arg=1";
String expectedResult = "https://old.host.dev/page?arg=1";

String urlWithTwoOccurences = "http://old.host.http.dev/page?arg=1";
String expectedResultWithTwoOccurences = "https://old.host.http.dev/page?arg=1";

Assert.AreEqual(url.ReplaceFirst("http", "https"), expectedResult);
Assert.AreEqual(urlWithTwoOccurences.ReplaceFirst("http", "https"), expectedResultWithTwoOccurences);
}
}
}
9 changes: 5 additions & 4 deletions Sitecore.SharedSource.DynamicSitemap.Tests/HelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public void TestEnsureHttpPrefix()
{
String urlWithHttp = "http://old.host.dev/page?arg=1";
String urlWithHttps = "https://old.host.dev/page?arg=1";
String urlWithoutHttp = "://old.host.dev/page?arg=1";
String urlWithoutProtocol = "://old.host.dev/page?arg=1";

Assert.AreEqual(DynamicSitemapHelper.EnsureHttpPrefix(urlWithHttp), urlWithHttp);
Assert.AreEqual(DynamicSitemapHelper.EnsureHttpPrefix(urlWithHttps), urlWithHttps);

Assert.AreEqual(DynamicSitemapHelper.EnsureHttpPrefix(urlWithoutHttp), "http" + urlWithoutHttp);
Assert.AreEqual(DynamicSitemapHelper.EnsureHttpPrefix(urlWithoutHttp, true), "https" + urlWithoutHttp);
Assert.AreEqual(DynamicSitemapHelper.EnsureHttpPrefix(urlWithHttp, true), "https" + urlWithoutHttp);
Assert.AreEqual(DynamicSitemapHelper.EnsureHttpPrefix(urlWithoutProtocol), "http" + urlWithoutProtocol);
Assert.AreEqual(DynamicSitemapHelper.EnsureHttpPrefix(urlWithoutProtocol, true), "https" + urlWithoutProtocol);
Assert.AreEqual(DynamicSitemapHelper.EnsureHttpPrefix(urlWithHttp, true), "https" + urlWithoutProtocol);
Assert.AreEqual(DynamicSitemapHelper.EnsureHttpPrefix(urlWithHttps, true), "https" + urlWithoutProtocol);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="ExtensionsTests.cs" />
<Compile Include="HelperTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Sitecore.SharedSource.DynamicSitemap/Constants/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class Messages

public static readonly String ExceptionWhileBuilding = Label + "Exception while building sitemap for {0} - {1}\n\n{2}";

public static readonly String SitemapBuidSuccess = Label + "Sitemap generated - {0}";
public static readonly String SitemapBuildSuccess = Label + "Sitemap generated - {0}";

public static readonly String SitemapSubmitterCannotSubmit = Label + "Cannot submit sitemap to \"{0}\" - {1}";
public static readonly String SitemapSubmitterExceptionWhileSubmit = Label + "Search engine submission \"{0}\" returns an error - {1} \n\n{2}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void ReadConfigurations()
}

/// <summary>
/// Read global SC configuration
/// Read global configuration from Sitecore
/// </summary>
protected void ReadGlobalSitecoreConfiguration()
{
Expand Down Expand Up @@ -280,7 +280,7 @@ public String BuildSitemap(SitemapSiteConfiguration sitemapSiteConfiguration)

result = stringWriter.ToString();

Sitecore.Diagnostics.Log.Info(String.Format(Messages.SitemapBuidSuccess, sitemapSiteConfiguration), this);
Sitecore.Diagnostics.Log.Info(String.Format(Messages.SitemapBuildSuccess, sitemapSiteConfiguration), this);
}

return result;
Expand Down Expand Up @@ -545,7 +545,7 @@ protected bool IsIncluded(Item item, SitemapSiteConfiguration sitemapSiteConfigu

if (!sitemapSiteConfiguration.ExcludedItems.Any(x => x == item.ID.ToString())
&& sitemapSiteConfiguration.IncludedTemplates.Contains(item.TemplateID.ToString())
&& !sitemapSiteConfiguration.ExcludedItemPaths.Any(x => item.Paths.FullPath.StartsWith(x.Paths.FullPath) && item.Paths.FullPath.Equals(x.Paths.FullPath))
&& !sitemapSiteConfiguration.ExcludedItemPaths.Any(x => item.Paths.FullPath.ToLower().StartsWith(x.Paths.FullPath.ToLower()) || item.Paths.FullPath.ToLower().Equals(x.Paths.FullPath.ToLower()))
&& (item.Paths.FullPath.StartsWith(sitemapSiteConfiguration.RootItem.Paths.FullPath)
|| item.Paths.FullPath.Equals(sitemapSiteConfiguration.RootItem.Paths.FullPath)
|| isDataSourceItem)) // - datasource items can be out of root item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public static String EnsureHttpPrefix(String url, bool useHttps = false)
{
url = (useHttps ? "https" : "http") + url;
}

else if (url.StartsWith("http") && useHttps)
else if (url.StartsWith("http") && !url.StartsWith("https") && useHttps)
{
url = url.ReplaceFirst("http", "https");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public String SitemapUrl
: Site.HostName;
}

url = url.Replace("//", "/");
//url = url.Replace("//", "/");
url = !url.StartsWith("http://")
? "http://" + url
: url;
Expand Down
12 changes: 12 additions & 0 deletions Sitecore.SharedSource.DynamicSitemap/Model/UrlElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ namespace Sitecore.SharedSource.DynamicSitemap.Model
/// </summary>
public class UrlElement
{
/// <summary>
/// The &lt;loc&gt; element
/// </summary>
public String Location { get; set; }

/// <summary>
/// The &lt;lastmod&gt; element
/// </summary>
public DateTime LastModification { get; set; }

/// <summary>
/// The &lt;changefreq&gt; element
/// </summary>
public String ChangeFrequency { get; set; }

/// <summary>
/// The &lt;priority&gt; element
/// </summary>
public String Priority { get; set; }
}
}

0 comments on commit 9a97e48

Please sign in to comment.