Skip to content

Commit

Permalink
Merge pull request #18 from unic/feature/preserve-casing-of-capture-g…
Browse files Browse the repository at this point in the history
…roups

Preserve casing of capture groups
  • Loading branch information
adamwroo authored Feb 10, 2022
2 parents 557ab75 + 3e26a97 commit e32511b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 21 deletions.
31 changes: 27 additions & 4 deletions be/GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
mode: ContinuousDelivery
branches: {}
ignore:
sha: []
assembly-versioning-scheme: MajorMinorPatch
mode: mainline
continuous-delivery-fallback-tag: ''
tag-prefix: '[vV]'
major-version-bump-message: '\+semver:\s?(dotnotuse)'
minor-version-bump-message: '\+semver:\s?(breaking|major)'
patch-version-bump-message: '\+semver:\s?(feature|minor)'
no-bump-message: '\+semver:\s?(none|skip)'
branches:
main:
tag: ''
increment: Patch
prevent-increment-of-merged-branch-version: true
regex: ^main$
is-release-branch: true
is-mainline: true
feature:
tag: ft
tag-number-pattern: '[/-](?<number>\d+)[-/]'
increment: Inherit
source-branches:
- main
is-mainline: false
pull-request:
tag: pull
tag-number-pattern: '[/-](?<number>\d+)[-/]'
merge-message-formats: {}
13 changes: 10 additions & 3 deletions be/src/Unic.UrlMapper2/code/Models/RedirectSearchData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@
{
public class RedirectSearchData
{
public string SourceTerm { get; set; }
public string SourceTerm { get; set; }

public string Language { get; set; }
/// <summary>
/// Source Term with the original casing
/// </summary>
public string SourceTermOriginal { get; set; }

public string SiteName { get; set; }
public string Language { get; set; }

public string SiteName { get; set; }

public string SourceProtocol { get; set; }

public RedirectSearchData(
string sourceTerm,
string sourceTermOriginal,
string language,
string siteName,
string sourceProtocol)
{
this.SourceTerm = sourceTerm;
this.SourceTermOriginal = sourceTermOriginal;
this.Language = language;
this.SiteName = siteName;
this.SourceProtocol = sourceProtocol;
Expand Down
4 changes: 2 additions & 2 deletions be/src/Unic.UrlMapper2/code/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.1.3.0")]
[assembly: AssemblyFileVersion("1.1.3.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
2 changes: 1 addition & 1 deletion be/src/Unic.UrlMapper2/code/Services/ISanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public interface ISanitizer
{
void SanitizeRedirectSearchData(RedirectSearchData redirectSearchData);

string SanitizeTerm(string value);
string SanitizeTerm(string value, bool convertToLower = true);

string SanitizeSiteName(string value);

Expand Down
22 changes: 16 additions & 6 deletions be/src/Unic.UrlMapper2/code/Services/RedirectSearchDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ public RedirectSearchDataService(
this.logger = logger;
}

public virtual RedirectSearchData GetDefaultRedirectSearchData(HttpRequestArgs args) =>
new RedirectSearchData(
sourceTerm: this.GetSourceTermForDefaultRedirectSearchData(args),
public virtual RedirectSearchData GetDefaultRedirectSearchData(HttpRequestArgs args)
{
var sourceTerm = this.GetSourceTermForDefaultRedirectSearchData(args);

return new RedirectSearchData(
sourceTerm: sourceTerm,
sourceTermOriginal: sourceTerm,
language: this.context.Language?.Name,
siteName: this.context.Site?.Name?.ToLower(),
sourceProtocol: this.GetSourceProtocolForDefaultRedirectSearchData(args));
}

protected virtual string GetSourceTermForDefaultRedirectSearchData(HttpRequestArgs args)
{
Expand All @@ -44,12 +49,17 @@ protected virtual string GetSourceTermForDefaultRedirectSearchData(HttpRequestAr
return startIndex < 0 ? default : args.RequestUrl.PathAndQuery.Substring(startIndex);
}

public virtual RedirectSearchData GetJssRedirectSearchData(HttpContextBase httpContext) =>
new RedirectSearchData(
sourceTerm: this.GetSourceTermForJssRedirectSearchData(httpContext),
public virtual RedirectSearchData GetJssRedirectSearchData(HttpContextBase httpContext)
{
var sourceTerm = this.GetSourceTermForJssRedirectSearchData(httpContext);

return new RedirectSearchData(
sourceTerm: sourceTerm,
sourceTermOriginal: sourceTerm,
language: this.context.Language?.Name,
siteName: this.context.Site?.Name,
sourceProtocol: this.GetSourceProtocolForJssRedirectSearchData(httpContext));
}

protected virtual string GetSourceProtocolForDefaultRedirectSearchData(HttpRequestArgs args)
{
Expand Down
2 changes: 1 addition & 1 deletion be/src/Unic.UrlMapper2/code/Services/RedirectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected virtual string GetAdditionalTargetUrlData(RedirectSearchData redirectS
{
if (!redirect.RegexEnabled) return default;

var match = Regex.Match(redirectSearchData.SourceTerm, redirect.Term);
var match = Regex.Match(redirectSearchData.SourceTermOriginal, redirect.Term, RegexOptions.IgnoreCase);
if (match.Groups.Count <= 1) return default;

string additionalTargetData = null;
Expand Down
7 changes: 4 additions & 3 deletions be/src/Unic.UrlMapper2/code/Services/Sanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ public class Sanitizer : ISanitizer
public virtual void SanitizeRedirectSearchData(RedirectSearchData redirectSearchData)
{
redirectSearchData.SourceTerm = this.SanitizeTerm(redirectSearchData.SourceTerm);
redirectSearchData.SourceTermOriginal = this.SanitizeTerm(redirectSearchData.SourceTermOriginal, false);
redirectSearchData.SiteName = this.SanitizeSiteName(redirectSearchData.SiteName);
redirectSearchData.SourceProtocol = this.SanitizeProtocol(redirectSearchData.SourceProtocol);
}

public virtual string SanitizeTerm(string value)
public virtual string SanitizeTerm(string value, bool convertToLower = true)
{
if (string.IsNullOrWhiteSpace(value)) return default;

value = value.Trim().ToLower();
value = value.Trim();

value = StringUtil.RemovePrefix('/', value);
value = StringUtil.RemovePostfix('/', value);

return value;
return convertToLower ? value.ToLower() : value;
}

public virtual string SanitizeSiteName(string value) => value?.Trim().ToLower();
Expand Down
9 changes: 8 additions & 1 deletion build/azure-templates/jobs-build-be.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ jobs:
artifactName: "solution-webroot.zip"

steps:
- task: GitVersion@5
- task: gitversion/setup@0
displayName: 'Install GitVersion'
inputs:
versionSpec: '5.8'
- task: gitversion/execute@0
displayName: 'Execute GitVersion'
inputs:
runtime: "full"
additionalArguments: "/updateassemblyinfo"
useConfigFile: true
configFilePath: 'be/GitVersion.yml'

# Install NuGet Tools
- task: NuGetToolInstaller@1
Expand Down

0 comments on commit e32511b

Please sign in to comment.