GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: normalize Windows drive paths by efegokdemir · Pull Request #387 · apache/maven-filtering

Conversation

@efegokdemir

@efegokdemir efegokdemir commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Correct the drive-path prefix check used by FilteringUtils.getRelativeFilePath().
  • Handle both slash and backslash prefixes and match the full path so /C:/... and \C:\... are normalized before drive comparison.

Testing

  • mvn -Dspotless.check.skip=true -Dspotless.apply.skip=true test — passed (76 tests)
  • git diff --check — passed

The standard Spotless invocation is blocked locally by the configured formatter failing with NoSuchFieldError under the available Java runtime; Spotless was skipped only for the test execution above.

Fixes #352

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gnodet-bot
gnodet-bot reviewed Sep 24, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good fix — the original regex ^\\[a-zA-Z]: was dead code (it matched a literal [ character, never a Windows path), so this is a meaningful improvement.

One minor edge case worth noting inline. The tests cover the primary use cases correctly.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

gnodet-bot
gnodet-bot suggested changes Sep 24, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Update after CI results: My previous review said "the tests cover the primary use cases correctly" — that was wrong. The Windows CI runs have since completed and they fail.

CI failure: FilteringUtilsTest.relativeFilePathStripsLeadingSeparatorFromWindowsDrivePath fails on both windows-latest jdk-21 and windows-latest jdk-25:

expected: <../other/file.txt> but was: <..\other\file.txt>

The second assertion uses a hardcoded forward-slash path (../other/file.txt) but getRelativeFilePath calls buildRelativePath(toPath, fromPath, File.separatorChar) — which uses File.separatorChar (\\ on Windows) to construct the result. The test passes on Linux/macOS (where File.separatorChar is /) but fails on Windows where the result contains backslashes.

The production fix to FilteringUtils.java itself looks correct — this is purely a test portability issue. But the test must pass on all platforms.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

gnodet-bot
gnodet-bot reviewed Sep 24, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Both issues from the previous review are addressed:

  • ✅ Dead regex fixed — the ^\\[a-zA-Z]: pattern (which matched a literal [) is replaced by ^[/\\][a-zA-Z]:[/\\].*, correctly requiring a separator after the drive letter.
  • ✅ Test assertion fixed — paths are normalized to forward slashes before passing to buildRelativePath, so the test assertion is correct cross-platform.

Two remaining observations:

1 · Regex has a dead backslash alternative (low)

After .replace('\\', '/') on lines 180–181, fromPath and toPath contain no backslashes. The \\ alternative inside [/\\] in both matches(...) calls can therefore never fire — it is dead code. The regex is functionally equivalent to ^/[a-zA-Z]:/.* at that point. Not a bug, but misleading: the \\ branch implies backslash paths are still possible when they aren't. Worth simplifying.

2 · No regression tests for the Javadoc Unix-path examples (medium)

The Javadoc documents several Unix-path contracts:

getRelativeFilePath("/usr/local", "/usr/local/java/bin")  = "java/bin"
getRelativeFilePath("/usr/local/", "/bin")                = "../../bin"
getRelativeFilePath("/bin", "/usr/local/")                = "../usr/local"

Before this PR, there were zero tests for getRelativeFilePath (it existed untested). The PR adds two Windows-specific tests but none for the documented Unix cases. Since the separator logic was changed (hardcoding '/' in buildRelativePath, adding a trailing-slash check), a regression is possible on a Windows JVM if these paths go through File.getPath() and pick up platform separators. Tests for the Javadoc examples should be added in the same PR.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

gnodet-bot
gnodet-bot reviewed Sep 24, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

All three findings from the previous review are addressed:

  • ✅ Dead backslash alternative in toPath.matches() — simplified to ^/[a-zA-Z]:/.*
  • ✅ Same for fromPath.matches()
  • ✅ Added relativeFilePathUnixStylePaths() covering the three Javadoc-documented cases

One remaining doc accuracy issue below.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

gnodet-bot
gnodet-bot approved these changes Sep 24, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

All three findings from the review history are now addressed:

  • ✅ Round 1: Dead regex (^\\[a-zA-Z]:) replaced with ^/[a-zA-Z]:/.*; Windows CI test failure fixed via .replace(’\\’, ’/’) normalization
  • ✅ Round 2: Dead backslash alternative in regex simplified; Unix-path regression tests added for all three Javadoc-documented cases
  • ✅ Round 3: Javadoc example corrected to "../usr/local/" (trailing slash preserved, matching actual behavior)

The Note update (line 12) is also accurate — after the replace(’\\’, ’/’) normalization the separator is always /, so the old note advising Windows callers to substitute \\ was stale and is now correctly removed.

Ready to merge.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gnodet
gnodet approved these changes Sep 24, 2026
View reviewed changes
@gnodet gnodet added bug Something isn't working java Pull requests that update Java code labels Sep 24, 2026
@gnodet
fix: normalize Windows drive paths in FilteringUtils
f622b47
- Replace backslash-prefixed drive paths (e.g. \C:\path) with
  forward-slash form (C:/path) before relative path computation
- Tighten Windows drive letter regex to require separator after colon
- Use forward slashes in getRelativeFilePath for cross-platform consistency
- Add Unix and Windows path test coverage
@gnodet
gnodet force-pushed the codex/issue-352-windows-path branch from dfddded to f622b47 Compare September 24, 2026 16:36
@gnodet
gnodet merged commit 4876d9e into apache:master Sep 24, 2026
@github-actions github-actions Bot added this to the 4.0.0-beta-2 milestone Sep 24, 2026
@github-actions github-actions Bot assigned gnodet Sep 24, 2026
@gnodet gnodet mentioned this pull request Sep 24, 2026
[Backport maven-filtering-3.x] Batch backport: #290, #386–#393 #396
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gnodet gnodet gnodet approved these changes
+1 more reviewer
@gnodet-bot gnodet-bot gnodet-bot approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gnodet gnodet

Labels

bug Something isn't working java Pull requests that update Java code

Projects

None yet

Milestone

4.0.0-beta-2

Development

Successfully merging this pull request may close these issues.

Broken Windows path regex in FilteringUtils.getRelativeFilePath()

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@efegokdemir @gnodet @gnodet-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.