From e25a81ef38547191e8d0cc72261df0f282545386 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Thu, 30 Jul 2020 13:54:28 +0200 Subject: [PATCH] V8: Wildcards in tree searches causes YSODs (#7330) --- .../Persistence/Querying/ExpressionVisitorBase.cs | 4 +++- src/Umbraco.Web/Search/UmbracoTreeSearcher.cs | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Persistence/Querying/ExpressionVisitorBase.cs b/src/Umbraco.Core/Persistence/Querying/ExpressionVisitorBase.cs index d04930fa92..f8acbdfade 100644 --- a/src/Umbraco.Core/Persistence/Querying/ExpressionVisitorBase.cs +++ b/src/Umbraco.Core/Persistence/Querying/ExpressionVisitorBase.cs @@ -744,7 +744,9 @@ namespace Umbraco.Core.Persistence.Querying var c = exp[0]; return (c == '"' || c == '`' || c == '\'') && exp[exp.Length - 1] == c - ? exp.Substring(1, exp.Length - 2) + ? exp.Length == 1 + ? string.Empty + : exp.Substring(1, exp.Length - 2) : exp; } } diff --git a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs index dcc156e356..a22e2a6f6a 100644 --- a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs +++ b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs @@ -186,6 +186,9 @@ namespace Umbraco.Web.Search var allLangs = _languageService.GetAllLanguages().Select(x => x.IsoCode.ToLowerInvariant()).ToList(); + // the chars [*-_] in the query will mess everything up so let's remove those + query = Regex.Replace(query, "[\\*\\-_]", ""); + //check if text is surrounded by single or double quotes, if so, then exact match var surroundedByQuotes = Regex.IsMatch(query, "^\".*?\"$") || Regex.IsMatch(query, "^\'.*?\'$");