Match neutral cultures as Examine culture fields (#9305)

This commit is contained in:
Ronald Barendse
2021-08-06 12:22:03 +02:00
committed by GitHub
parent f4f6350879
commit 40d8e11ba7
2 changed files with 6 additions and 6 deletions

View File

@@ -27,7 +27,7 @@ namespace Umbraco.Examine
/// <remarks>
/// myFieldName_en-us will match the "en-us"
/// </remarks>
internal static readonly Regex CultureIsoCodeFieldNameMatchExpression = new Regex("^([_\\w]+)_([a-z]{2}-[a-z0-9]{2,4})$", RegexOptions.Compiled);
internal static readonly Regex CultureIsoCodeFieldNameMatchExpression = new Regex("^(?<FieldName>[_\\w]+)_(?<CultureName>[a-z]{2,3}(-[a-z0-9]{2,4})?)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
private static bool _isConfigured = false;
private static object _configuredInit = null;
@@ -67,7 +67,7 @@ namespace Umbraco.Examine
foreach (var field in allFields)
{
var match = CultureIsoCodeFieldNameMatchExpression.Match(field);
if (match.Success && match.Groups.Count == 3 && culture.InvariantEquals(match.Groups[2].Value))
if (match.Success && culture.InvariantEquals(match.Groups["CultureName"].Value))
yield return field;
}
}
@@ -85,7 +85,7 @@ namespace Umbraco.Examine
foreach (var field in allFields)
{
var match = CultureIsoCodeFieldNameMatchExpression.Match(field);
if (match.Success && match.Groups.Count == 3 && culture.InvariantEquals(match.Groups[2].Value))
if (match.Success && culture.InvariantEquals(match.Groups["CultureName"].Value))
{
yield return field; //matches this culture field
}

View File

@@ -73,13 +73,13 @@ namespace Umbraco.Examine
return true;
//before we use regex to match do some faster simple matching since this is going to execute quite a lot
if (!fieldName.Contains("_") || !fieldName.Contains("-"))
if (!fieldName.Contains("_"))
return false;
var match = ExamineExtensions.CultureIsoCodeFieldNameMatchExpression.Match(fieldName);
if (match.Success && match.Groups.Count == 3)
if (match.Success)
{
var nonCultureFieldName = match.Groups[1].Value;
var nonCultureFieldName = match.Groups["FieldName"].Value;
//check if there's a definition for this and if so return the field definition for the culture field based on the non-culture field
if (base.TryGetValue(nonCultureFieldName, out var existingFieldDefinition))
{