Skip to content

Commit fe3d3e6

Browse files
committed
Fixes encoding issues
1 parent 8124ec0 commit fe3d3e6

3 files changed

Lines changed: 30 additions & 27 deletions

File tree

src/Libraries/SmartStore.Core/Extensions/StringExtensions.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,11 +1087,8 @@ public static string ReplaceCsvChars(this string s)
10871087
[DebuggerStepThrough]
10881088
public static string HighlightKeywords(this string input, string keywords, string preMatch = "<strong>", string postMatch = "</strong>")
10891089
{
1090-
if (preMatch == null)
1091-
throw new ArgumentNullException(nameof(preMatch));
1092-
1093-
if (postMatch == null)
1094-
throw new ArgumentNullException(nameof(postMatch));
1090+
Guard.NotNull(preMatch, nameof(preMatch));
1091+
Guard.NotNull(postMatch, nameof(postMatch));
10951092

10961093
if (string.IsNullOrWhiteSpace(input) || string.IsNullOrWhiteSpace(keywords))
10971094
{
@@ -1107,7 +1104,7 @@ public static string HighlightKeywords(this string input, string keywords, strin
11071104
if (!string.IsNullOrWhiteSpace(pattern))
11081105
{
11091106
var rg = new Regex(pattern, RegexOptions.IgnoreCase);
1110-
input = rg.Replace(input, m => preMatch + m.Value + postMatch);
1107+
input = rg.Replace(input, m => preMatch + m.Value.EmptyNull().HtmlEncode() + postMatch);
11111108
}
11121109

11131110
return input;

src/Presentation/SmartStore.Web/Views/Boards/Search.cshtml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,33 @@
33
@using SmartStore.Web.Framework.UI;
44
@model ForumSearchResultModel
55
@{
6-
Layout = "_Layout";
6+
var suggestions = new string[0];
7+
var encodedTerm = Model.Term.EmptyNull().HtmlEncode();
8+
var encodedAttemptedTerm = Model.AttemptedTerm.EmptyNull().HtmlEncode();
79

8-
if (Model.Term.HasValue())
10+
if (encodedTerm.HasValue())
911
{
10-
Html.AddTitleParts(T("Search.PageTitle", "\"" + Model.Term + "\""));
12+
Html.AddTitleParts(T("Search.PageTitle", "\"" + encodedTerm + "\""));
1113
}
1214
else
1315
{
1416
Html.AddTitleParts(T("Forum.Search"));
1517
}
1618

17-
var suggestions = new string[0];
1819
if (Model.TotalCount > 0)
1920
{
2021
suggestions = Model.SearchResult.SpellCheckerSuggestions;
2122
}
23+
24+
Layout = "_Layout";
2225
}
2326

2427
<div class="page forum-search">
2528
<div class="page-title">
2629
<h1 class="h3">
27-
@if (Model.Term.HasValue())
30+
@if (encodedTerm.HasValue())
2831
{
29-
@T("Search.PageTitle", "<small class='search-term'>" + Model.Term + "</small>")
32+
@T("Search.PageTitle", "<small class='search-term'>" + encodedTerm + "</small>")
3033
}
3134
else
3235
{
@@ -48,10 +51,10 @@
4851
@{ Html.RenderAction("SearchBox", "Boards"); }
4952
</div>
5053

51-
@if (Model.AttemptedTerm.HasValue())
54+
@if (encodedAttemptedTerm.HasValue())
5255
{
5356
<div class="alert alert-warning">
54-
@T("Search.TermCorrectedHint", "<strong>\"" + Model.Term + "\"</strong>", "<strong>\"" + Model.AttemptedTerm + "\"</strong>")
57+
@T("Search.TermCorrectedHint", "<strong>\"" + encodedTerm + "\"</strong>", "<strong>\"" + encodedAttemptedTerm + "\"</strong>")
5558
</div>
5659
}
5760

@@ -61,7 +64,7 @@
6164
@Model.Error
6265
</div>
6366
}
64-
else if (Model.TotalCount == 0 && Model.Term.HasValue())
67+
else if (Model.TotalCount == 0 && encodedTerm.HasValue())
6568
{
6669
<div class="alert alert-info">
6770
@T("Forum.SearchNoResultsText")
@@ -71,7 +74,7 @@
7174
@if (suggestions.Any())
7275
{
7376
<p class="search-suggestions">
74-
<strong>@(T(Model.AttemptedTerm.HasValue() || Model.TotalCount == 0 ? "Search.DidYouMean" : "Search.RelatedSearchTerms")):</strong>
77+
<strong>@(T(encodedAttemptedTerm.HasValue() || Model.TotalCount == 0 ? "Search.DidYouMean" : "Search.RelatedSearchTerms")):</strong>
7578
@{
7679
var links = string.Join(", ", suggestions.Select(x => "<a href='" + Url.RouteUrl("BoardSearch", new { q = x }) + "'>{0}</a>".FormatCurrentUI(x)));
7780
}
@@ -134,7 +137,7 @@
134137
countHtml += "<span class='more-hits-sign'>+</span>";
135138
}
136139

137-
@T("Search.HitsFor", countHtml, "<b class='font-weight-medium'>{0}</b>".FormatInvariant(Model.Term.NaIfEmpty()))
140+
@T("Search.HitsFor", countHtml, "<b class='font-weight-medium'>{0}</b>".FormatInvariant(Model.Term.NaIfEmpty().HtmlEncode()))
138141
}
139142

140143
<script type="text/javascript">

src/Presentation/SmartStore.Web/Views/Search/Search.cshtml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33

44
@model SearchResultModel
55
@{
6-
if (Model.Term.HasValue())
6+
var firstItemIndex = 0;
7+
var lastItemIndex = 0;
8+
var suggestions = new string[0];
9+
var encodedTerm = Model.Term.EmptyNull().HtmlEncode();
10+
var encodedAttemptedTerm = Model.AttemptedTerm.EmptyNull().HtmlEncode();
11+
12+
if (encodedTerm.HasValue())
713
{
8-
Html.AddTitleParts(T("Search.PageTitle", "\"" + Model.Term + "\""));
14+
Html.AddTitleParts(T("Search.PageTitle", "\"" + encodedTerm + "\""));
915
}
1016
else
1117
{
1218
Html.AddTitleParts(T("Search.Title"));
1319
}
1420

15-
int firstItemIndex = 0;
16-
int lastItemIndex = 0;
17-
var suggestions = new string[0];
1821
if (Model.TotalProductsCount > 0)
1922
{
2023
firstItemIndex = Model.SearchResult.Hits.FirstItemIndex;
@@ -39,9 +42,9 @@
3942
<div class="page search-page">
4043
<div class="page-title">
4144
<h1 class="h3">
42-
@if (Model.Term.HasValue())
45+
@if (encodedTerm.HasValue())
4346
{
44-
@T("Search.PageTitle", "<small class='search-term'>" + Model.Term + "</small>")
47+
@T("Search.PageTitle", "<small class='search-term'>" + encodedTerm + "</small>")
4548
}
4649
else
4750
{
@@ -55,10 +58,10 @@
5558
</div>
5659

5760
<div class="page-body">
58-
@if (Model.AttemptedTerm.HasValue())
61+
@if (encodedAttemptedTerm.HasValue())
5962
{
6063
<div class="alert alert-warning">
61-
@T("Search.TermCorrectedHint", "<strong>\"" + Model.Term + "\"</strong>", "<strong>\"" + Model.AttemptedTerm + "\"</strong>")
64+
@T("Search.TermCorrectedHint", "<strong>\"" + encodedTerm + "\"</strong>", "<strong>\"" + encodedAttemptedTerm + "\"</strong>")
6265
</div>
6366
}
6467

@@ -78,7 +81,7 @@
7881
@if (suggestions.Any())
7982
{
8083
<p class="search-suggestions">
81-
<strong>@(T(Model.AttemptedTerm.HasValue() || Model.TotalProductsCount == 0 ? "Search.DidYouMean" : "Search.RelatedSearchTerms")):</strong>
84+
<strong>@(T(encodedAttemptedTerm.HasValue() || Model.TotalProductsCount == 0 ? "Search.DidYouMean" : "Search.RelatedSearchTerms")):</strong>
8285
@{
8386
var links = String.Join(", ", suggestions.Select(x => "<a href='" + Url.RouteUrl("Search", new { q = x }) + "'>{0}</a>".FormatCurrentUI(x)));
8487
}

0 commit comments

Comments
 (0)