Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Align tests with moved InputSanitizer.cs and StringFormatWithExtensio…
…n.cs
  • Loading branch information
9swampy authored and arturcic committed Aug 9, 2025
commit 16ff852a500cdef3add93d4d84c6eb0cdd22f064
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GitVersion.Core.Tests.Helpers;
using GitVersion.Helpers;
using GitVersion.Formatting;

namespace GitVersion.Core.Tests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GitVersion.Core.Tests.Extensions;
using GitVersion.Helpers;
using GitVersion.Formatting;

namespace GitVersion.Tests.Helpers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GitVersion.Core.Tests.Extensions;
using GitVersion.Helpers;
using GitVersion.Formatting;

namespace GitVersion.Tests.Helpers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GitVersion.Core.Tests.Extensions;
using GitVersion.Helpers;
using GitVersion.Formatting;

namespace GitVersion.Tests.Helpers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GitVersion.Core.Tests.Extensions;
using GitVersion.Helpers;
using GitVersion.Formatting;

namespace GitVersion.Tests.Helpers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GitVersion.Helpers
namespace GitVersion.Formatting
{
internal interface IInputSanitizer
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,47 @@
using GitVersion.Core;

namespace GitVersion.Helpers;
namespace GitVersion.Formatting;

internal class InputSanitizer : IInputSanitizer
{
public string SanitizeFormat(string format)
{
if (string.IsNullOrWhiteSpace(format))
{
throw new FormatException("Format string cannot be empty.");
}

if (format.Length > 50)
{
throw new FormatException($"Format string too long: '{format[..20]}...'");
}

if (format.Any(c => char.IsControl(c) && c != '\t'))
{
throw new FormatException("Format string contains invalid control characters");
}

return format;
}

public string SanitizeEnvVarName(string name)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException("Environment variable name cannot be null or empty.");
}

if (name.Length > 200)
{
throw new ArgumentException($"Environment variable name too long: '{name[..20]}...'");
}

if (!RegexPatterns.Cache.GetOrAdd(RegexPatterns.Common.SanitizeEnvVarNameRegexPattern).IsMatch(name))
{
throw new ArgumentException($"Environment variable name contains disallowed characters: '{name}'");
}

return name;
}

public string SanitizeMemberName(string memberName)
{
if (string.IsNullOrWhiteSpace(memberName))
{
throw new ArgumentException("Member name cannot be empty.");
}

if (memberName.Length > 100)
{
throw new ArgumentException($"Member name too long: '{memberName[..20]}...'");
}

if (!RegexPatterns.Cache.GetOrAdd(RegexPatterns.Common.SanitizeMemberNameRegexPattern).IsMatch(memberName))
{
throw new ArgumentException($"Member name contains disallowed characters: '{memberName}'");
}

return memberName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Text.RegularExpressions;
using GitVersion.Core;
using GitVersion.Formatting;

namespace GitVersion.Helpers;
namespace GitVersion.Formatting;

internal static class StringFormatWithExtension
{
Expand Down Expand Up @@ -59,9 +58,7 @@ private static string EvaluateMatch<T>(Match match, T source, IEnvironment envir
var fallback = match.Groups["fallback"].Success ? match.Groups["fallback"].Value : null;

if (match.Groups["envvar"].Success)
{
return EvaluateEnvVar(match.Groups["envvar"].Value, fallback, environment);
}

if (match.Groups["member"].Success)
{
Expand All @@ -88,9 +85,7 @@ private static string EvaluateMember<T>(T source, string member, string? format,
var value = getter(source);

if (value is null)
{
return fallback ?? string.Empty;
}

if (format is not null && ValueFormatter.Default.TryFormat(
value,
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/VersionCalculation/VariableProvider.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using GitVersion.Configuration;
using GitVersion.Core;
using GitVersion.Extensions;
using GitVersion.Helpers;
using GitVersion.Formatting;
using GitVersion.OutputVariables;

namespace GitVersion.VersionCalculation;
Expand Down
1 change: 1 addition & 0 deletions src/GitVersion.Output/OutputGenerator/OutputGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO.Abstractions;
using GitVersion.Agents;
using GitVersion.Extensions;
using GitVersion.Formatting;
using GitVersion.Helpers;
using GitVersion.Logging;
using GitVersion.OutputVariables;
Expand Down