Skip to content

Commit c3f744c

Browse files
authored
Merge pull request #24 from unic/feature/fix-bug-in-preserve-query-string
Check if source term value is not null
2 parents d280e3e + 2069f7c commit c3f744c

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

be/src/Unic.UrlMapper2/code/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
//
3131
// You can specify all the values or you can default the Revision and Build Numbers
3232
// by using the '*' as shown below:
33-
[assembly: AssemblyVersion("1.3.0.0")]
34-
[assembly: AssemblyFileVersion("1.3.0.0")]
33+
[assembly: AssemblyVersion("1.3.1.0")]
34+
[assembly: AssemblyFileVersion("1.3.1.0")]

be/src/Unic.UrlMapper2/code/Services/RedirectSearcher.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ protected virtual Redirect MapToSearchResult(RedirectSearchResultItem redirectSe
6363
this.logger.Error($"Failed to parse source protocol {redirectSearchResultItem.SourceProtocol}", this);
6464
}
6565

66+
var sourceTerm = redirectSearchResultItem.SourceTerm;
6667
var redirect = new Redirect
6768
{
6869
RedirectSearchData = redirectSearchData,
@@ -71,21 +72,22 @@ protected virtual Redirect MapToSearchResult(RedirectSearchResultItem redirectSe
7172
SourceProtocol = sourceProtocol,
7273
RegexEnabled = redirectSearchResultItem.RegexEnabled,
7374
PreserveQueryString = redirectSearchResultItem.PreserveQueryString,
74-
Term = redirectSearchResultItem.SourceTerm
75+
Term = sourceTerm
7576
};
7677

77-
this.HandlePreserveQueryString(redirect, redirectSearchResultItem);
78+
this.HandlePreserveQueryString(redirect, sourceTerm);
7879
return redirect;
7980
}
8081

81-
protected virtual void HandlePreserveQueryString(Redirect redirect, RedirectSearchResultItem redirectSearchResultItem)
82+
protected virtual void HandlePreserveQueryString(Redirect redirect, string sourceTerm)
8283
{
8384
if (!redirect.PreserveQueryString) return;
8485

8586
redirect.RegexEnabled = true;
86-
if (!redirectSearchResultItem.SourceTerm.EndsWith(Constants.RegularExpressions.QueryStringExpression))
87+
if (!string.IsNullOrWhiteSpace(sourceTerm)
88+
&& !sourceTerm.EndsWith(Constants.RegularExpressions.QueryStringExpression))
8789
{
88-
redirect.Term = redirectSearchResultItem.SourceTerm + Constants.RegularExpressions.QueryStringExpression;
90+
redirect.Term = sourceTerm + Constants.RegularExpressions.QueryStringExpression;
8991
}
9092
}
9193

be/src/Unic.UrlMapper2/code/Services/RedirectionService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ protected virtual Redirect GetRegexMatch(RedirectSearchData redirectSearchData,
102102
if (string.IsNullOrWhiteSpace(sourceTerm)) return default;
103103

104104
// We are going to take the one regex redirect which has the longest match within the term
105-
var regexMatches = enumerableRedirects.Where(r => r.RegexEnabled && Regex.IsMatch(input: sourceTerm, pattern: r.Term));
106-
var regexMatch = regexMatches.OrderByDescending(r => r.Term.Length).FirstOrDefault();
105+
var regexMatches = enumerableRedirects.Where(r => r.RegexEnabled && !string.IsNullOrWhiteSpace(r.Term) && Regex.IsMatch(input: sourceTerm, pattern: r.Term));
106+
var regexMatch = regexMatches.OrderByDescending(r => r.Term?.Length).FirstOrDefault();
107107

108108
return regexMatch;
109109
}

0 commit comments

Comments
 (0)