Mercurial: Windows Filename Validation Consistency

Platform: Mercurial · Type: Bug fix / Cross-platform behavior · Status: Patch submitted · Issue: #10099

Context

Mercurial performs validation of file paths to ensure compatibility with Windows filesystem rules. Certain characters and patterns are disallowed, including trailing backslashes and reserved names.

However, validation behavior was inconsistent when handling backslashes in different positions within a path.

Problem

Filenames ending with a backslash correctly triggered a warning:

filename ends with '\', which is invalid on Windows

But filenames containing a backslash inside a path segment (e.g. bl\ank) did not produce any warning.

This inconsistency meant that invalid Windows paths could silently pass validation depending on how separators were used.

My Contribution

I updated the checkwinfilename validation logic to ensure that backslashes inside path segments are consistently detected when paths use forward slashes.

The fix introduces an additional validation step before normalization:

This ensures consistent behavior across mixed path formats and prevents silent acceptance of invalid Windows filenames.

Testing

I added a regression test in test-windows.t to verify that filenames containing embedded backslashes now correctly produce a warning.

This ensures the behavior remains consistent in future changes.

Process & Workflow

Unlike typical Git-based workflows, Mercurial contributions are often submitted as patches rather than pull requests.

I created a changeset locally and exported it using:

hg export tip > backslash-fix.patch

The patch was then attached directly to the issue for review by maintainers.

Reflection

This contribution highlights the importance of consistent validation logic across platforms. Small inconsistencies in edge cases can lead to confusing behavior for users.

It also provided hands-on experience with Mercurial’s patch-based contribution workflow and reinforced the value of adding targeted regression tests.