Skip to content

Commit

Permalink
Unify seperator in Script and Tag Helper (#17387)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Jan 23, 2025
1 parent 93a6dd0 commit adda289
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OrchardCore.ResourceManagement;

internal static class ResourceManagementConstants
{
public static readonly char[] ParameterValuesSeparator = [',', ' '];

public const char VersionSeparator = ':';
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace OrchardCore.ResourceManagement.TagHelpers;
[HtmlTargetElement("script", Attributes = AtAttributeName)]
public class ScriptTagHelper : TagHelper
{
private static readonly char[] _separator = [',', ' '];

private const string NameAttributeName = "asp-name";
private const string SrcAttributeName = "asp-src";
private const string AtAttributeName = "at";
Expand Down Expand Up @@ -108,7 +106,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
// This allows additions to the pre registered scripts dependencies.
if (!string.IsNullOrEmpty(DependsOn))
{
setting.SetDependencies(DependsOn.Split(_separator, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
setting.SetDependencies(DependsOn.Split(ResourceManagementConstants.ParameterValuesSeparator, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
}

// Allow Inline to work with both named scripts, and named inline scripts.
Expand Down Expand Up @@ -161,11 +159,11 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu

if (!string.IsNullOrEmpty(DependsOn))
{
var dependencies = DependsOn.Split(_separator, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
var dependencies = DependsOn.Split(ResourceManagementConstants.ParameterValuesSeparator, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);

foreach (var dependency in dependencies)
{
var versionParts = dependency.Split(':');
var versionParts = dependency.Split(ResourceManagementConstants.VersionSeparator, 2);

var resourceName = versionParts[0];

Expand Down Expand Up @@ -215,12 +213,12 @@ private void PopulateResourceDefinition(ResourceDefinition definition)

if (!string.IsNullOrEmpty(Culture))
{
definition.SetCultures(Culture.Split(_separator, StringSplitOptions.RemoveEmptyEntries));
definition.SetCultures(Culture.Split(ResourceManagementConstants.ParameterValuesSeparator, StringSplitOptions.RemoveEmptyEntries));
}

if (!string.IsNullOrEmpty(DependsOn))
{
definition.SetDependencies(DependsOn.Split(_separator, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
definition.SetDependencies(DependsOn.Split(ResourceManagementConstants.ParameterValuesSeparator, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
}

if (AppendVersion.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace OrchardCore.ResourceManagement.TagHelpers;
[HtmlTargetElement("style", Attributes = AtAttributeName)]
public class StyleTagHelper : TagHelper
{
private static readonly char[] _splitSeparators = [',', ' '];
private const string NameAttributeName = "asp-name";
private const string SrcAttributeName = "asp-src";
private const string AtAttributeName = "at";
Expand Down Expand Up @@ -94,7 +93,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu

if (!string.IsNullOrEmpty(DependsOn))
{
setting.SetDependencies(DependsOn.Split(_splitSeparators, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
setting.SetDependencies(DependsOn.Split(ResourceManagementConstants.ParameterValuesSeparator, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
}

if (At == ResourceLocation.Inline)
Expand Down Expand Up @@ -158,7 +157,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
// This allows additions to the pre registered style dependencies.
if (!string.IsNullOrEmpty(DependsOn))
{
setting.SetDependencies(DependsOn.Split(_splitSeparators, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
setting.SetDependencies(DependsOn.Split(ResourceManagementConstants.ParameterValuesSeparator, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
}

var childContent = await output.GetChildContentAsync();
Expand Down Expand Up @@ -200,12 +199,12 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu

if (!string.IsNullOrEmpty(Culture))
{
definition.SetCultures(Culture.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
definition.SetCultures(Culture.Split(ResourceManagementConstants.ParameterValuesSeparator, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
}

if (!string.IsNullOrEmpty(DependsOn))
{
definition.SetDependencies(DependsOn.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
definition.SetDependencies(DependsOn.Split(ResourceManagementConstants.ParameterValuesSeparator, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
}

// Also include the style.
Expand Down Expand Up @@ -256,11 +255,11 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu

if (!string.IsNullOrEmpty(DependsOn))
{
var dependencies = DependsOn.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
var dependencies = DependsOn.Split(ResourceManagementConstants.ParameterValuesSeparator, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);

foreach (var dependency in dependencies)
{
var versionParts = dependency.Split(':');
var versionParts = dependency.Split(ResourceManagementConstants.VersionSeparator, 2);

var resourceName = versionParts[0];

Expand Down

0 comments on commit adda289

Please sign in to comment.