Skip to content

Align PathHelpers.SafePathCombine with TemplateDotNetTool secure implementation#99

Merged
Malcolmnixon merged 2 commits intomainfrom
copilot/check-path-helpers-implementation
Mar 1, 2026
Merged

Align PathHelpers.SafePathCombine with TemplateDotNetTool secure implementation#99
Malcolmnixon merged 2 commits intomainfrom
copilot/check-path-helpers-implementation

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

Pull Request

Description

PathHelpers.SafePathCombine was missing the null-argument guards present in the TemplateDotNetTool reference implementation. Without these, a null input produces an uncontrolled NullReferenceException rather than a descriptive ArgumentNullException.

  • PathHelpers.cs — Added ArgumentNullException.ThrowIfNull for both basePath and relativePath at method entry. The implementation is now identical to TemplateDotNetTool apart from the namespace.
// Before: no null validation
internal static string SafePathCombine(string basePath, string relativePath)
{
    if (relativePath.Contains("..") || ...

// After: matches TemplateDotNetTool
internal static string SafePathCombine(string basePath, string relativePath)
{
    // Validate inputs
    ArgumentNullException.ThrowIfNull(basePath);
    ArgumentNullException.ThrowIfNull(relativePath);

    if (relativePath.Contains("..") || ...
  • PathHelpersTests.cs — Added two tests covering null basePath and null relativePath, each asserting the correct ParamName on the thrown exception.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code quality improvement

Related Issues

Pre-Submission Checklist

Before submitting this pull request, ensure you have completed the following:

Build and Test

  • Code builds successfully: dotnet build --configuration Release
  • All tests pass: dotnet test --configuration Release
  • Code produces zero warnings

Code Quality

  • Code formatting is correct: dotnet format --verify-no-changes
  • New code has appropriate XML documentation comments
  • Static analyzer warnings have been addressed

Quality Checks

Please run the following checks before submitting:

  • Spell checker passes: cspell "**/*.{md,cs}"
  • Markdown linter passes: markdownlint "**/*.md"
  • YAML linter passes: yamllint '**/*.{yml,yaml}'

Testing

  • Added unit tests for new functionality
  • Updated existing tests if behavior changed
  • All tests follow the AAA (Arrange, Act, Assert) pattern
  • Test coverage is maintained or improved

Documentation

  • Updated README.md (if applicable)
  • Updated ARCHITECTURE.md (if applicable)
  • Added code examples for new features (if applicable)
  • Updated requirements.yaml (if applicable)

Additional Notes

CodeQL reports 0 alerts after these changes.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

… ParamName in tests

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copilot AI changed the title [WIP] Review PathHelpers implementation for security improvements Align PathHelpers.SafePathCombine with TemplateDotNetTool secure implementation Mar 1, 2026
@Malcolmnixon Malcolmnixon marked this pull request as ready for review March 1, 2026 01:08
@Malcolmnixon Malcolmnixon merged commit 6e5c712 into main Mar 1, 2026
11 checks passed
@Malcolmnixon Malcolmnixon deleted the copilot/check-path-helpers-implementation branch March 1, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants