Skip to content

Align path prefix checks with platform case sensitivity - #227

Merged
ForNeVeR merged 2 commits into
ForNeVeR:mainfrom
amirani8137:fix/225-platform-prefix-comparison
Sep 21, 2026
Merged

ForNeVeR merged 2 commits into
ForNeVeR:mainfrom
amirani8137:fix/225-platform-prefix-comparison

Conversation

@amirani8137

Copy link
Copy Markdown
Contributor

Fixes #225.

Path prefix checks now use the same platform-default case sensitivity as path equality. This keeps IsPrefixOf and StartsWith consistent with Equals while preserving whole-path-segment matching.

Updated the API documentation and added cross-platform tests.

Validation:

  • dotnet build — passed
  • dotnet test — passed

@ForNeVeR
ForNeVeR self-requested a review September 20, 2026 15:59
@ForNeVeR ForNeVeR self-assigned this Sep 20, 2026
Comment thread TruePath.Tests/AbsolutePathTests.cs Outdated
Comment on lines +160 to +174
[Theory]
[InlineData("Foo", "foo")]
[InlineData("Foo", "foo/file.txt")]
[InlineData("Foo", "foobar")]
public void IsPrefixOfFollowsPlatformDefaultCaseSensitivity(string prefix, string other)
{
var root = new AbsolutePath(OperatingSystem.IsWindows() ? @"A:\" : "/");
var a = root / prefix;
var b = root / other;
var expected = (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) && other != "foobar";

Assert.Equal(expected, a.IsPrefixOf(b));
Assert.Equal(expected, b.StartsWith(a));
if (other == "foo") Assert.Equal(a == b, a.IsPrefixOf(b));
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

A bit too complex, I don't like checks for OS and other == "foobar" / other == "foo" in the test body. Perhaps it's be better to have three separate tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Split it into 3 separate tests, with the OS check moved into a Utils.IsPlatformCaseInsensitive() helper.

Comment thread TruePath.Tests/LocalPathTests.cs Outdated
Comment on lines +73 to +75
var startsWith = b.Value.StartsWith(a.Value, OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()
? StringComparison.OrdinalIgnoreCase
: StringComparison.Ordinal);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think this should be better replaced with b.StartsWith(a).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review. It's Done, now uses b.StartsWith(a).

Comment thread TruePath.Tests/LocalPathTests.cs Outdated
Comment on lines +120 to +133
[Theory]
[InlineData("Foo", "foo")]
[InlineData("Foo", "foo/bar")]
[InlineData("Foo", "foobar")]
public void IsPrefixOfFollowsPlatformDefaultCaseSensitivity(string prefix, string other)
{
var a = new LocalPath(prefix);
var b = new LocalPath(other);
var expected = (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) && other != "foobar";

Assert.Equal(expected, a.IsPrefixOf(b));
Assert.Equal(expected, b.StartsWith(a));
if (other == "foo") Assert.Equal(a == b, a.IsPrefixOf(b));
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Same comment as on the AbsolutePathTests: let's somehow get rid of the checks for particular cases inside of the test body.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

split it into three tests with no per-case checks in the body

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@ForNeVeR
ForNeVeR self-requested a review September 21, 2026 22:49

@ForNeVeR ForNeVeR left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks!

@ForNeVeR
ForNeVeR merged commit e845a31 into ForNeVeR:main Sep 21, 2026
10 checks passed
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.

IsPrefixOf/StartsWith compare ordinally while Equals follows the platform default

2 participants