Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions framework/src/Volo.Abp.BlazoriseUI/AbpBlazoriseUIModule.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Blazorise;
using Blazorise.Utilities;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.Application;
using Volo.Abp.AspNetCore.Components.Web;
using Volo.Abp.Authorization;
using Volo.Abp.BlazoriseUI.Utilities;
using Volo.Abp.Features;
using Volo.Abp.GlobalFeatures;
using Volo.Abp.Modularity;
Expand Down Expand Up @@ -34,6 +36,7 @@ private void ConfigureBlazorise(ServiceConfigurationContext context)
});

context.Services.Replace(ServiceDescriptor.Scoped<IComponentActivator, ComponentActivator>());
context.Services.Replace(ServiceDescriptor.Singleton<IValidationMessageLocalizerAttributeFinder, AbpValidationMessageLocalizerAttributeFinder>());
context.Services.AddSingleton(typeof(AbpBlazorMessageLocalizerHelper<>));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Blazorise.Utilities;
using Volo.Abp.DependencyInjection;

namespace Volo.Abp.BlazoriseUI.Utilities;

[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(AbpValidationMessageLocalizerAttributeFinder), typeof(IValidationMessageLocalizerAttributeFinder))]
public class AbpValidationMessageLocalizerAttributeFinder : IValidationMessageLocalizerAttributeFinder, ISingletonDependency
{
public IEnumerable<(string Index, string Argument)> FindAll(string first, string second)
{
if (string.IsNullOrEmpty(first) || string.IsNullOrEmpty(second))
{
yield break;
}

if (first == second)
{
yield break;
}

const string placeholderPattern = @"\{(\d+)\}";
var matches = Regex.Matches(second, placeholderPattern);

if (matches.Count == 0)
{
yield break;
}

var placeholderIndices = new List<string>();
foreach (Match match in matches)
{
placeholderIndices.Add(match.Groups[1].Value);
}

var pattern = placeholderIndices.Aggregate(second, (current, index) => current.Replace("{" + index + "}", "(.+)"));

var valueMatch = Regex.Match(first, pattern);
Comment on lines +39 to +41
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern on line 39 replaces placeholder indices but does not escape special regex characters that might be present in the localized string. If the 'second' parameter contains regex special characters (like '.', '*', '+', etc.), it could lead to incorrect pattern matching or regex errors. Consider escaping the 'second' string before using it in regex operations.

Copilot uses AI. Check for mistakes.
if (!valueMatch.Success)
{
yield break;
}

for (var i = 0; i < placeholderIndices.Count && i + 1 < valueMatch.Groups.Count; i++)
{
yield return (placeholderIndices[i], valueMatch.Groups[i + 1].Value);
}
}
}
Loading