Repository navigation
fix(path): ignore anything trailing the file name in set_extension - #68
Merged
Merged
Conversation
`set_extension` assumed the old extension sat at the very end of the raw buffer, so a path with a trailing separator had bytes chopped off the wrong place: `a.bc/` with extension `z` became `a.b.z`, and `a.bc/////` became `a.bc///.z`. Truncate at the end of the file stem instead, which is where `std::path` truncates. Anything trailing the file name -- separators, a current directory segment -- is discarded along with the old extension, so `a.bc/` now becomes `a.z`. As a side effect, an empty extension now removes a trailing `.` (`foo.` becomes `foo`), also matching `std::path`. Fixes #67 Claude-Session: https://claude.ai/code/session_01A5uCQTmXn119ATyfP27hfe
chipsenkbeil
force-pushed
the
fix/set-extension-trailing-separators
branch
from
August 28, 2026 04:56
057ed9e to
518f42a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #67.
The bug
_set_extensionassumed the old extension sat at the very end of the raw buffer:That holds only when the file name is the last thing in the buffer. With a trailing
separator the truncation lands in the middle of the file name instead:
.with_extension("z")beforestd::path/ aftera.bc/a.b.za.za.bc/////a.bc///.za.ztest.reallylongext/+"a"test.r.atest.aThe fix
Truncate at the end of the file stem, which is what
std::path::PathBuf::set_extensiondoes. The stem is a subslice of the buffer, so its end offset is the correct cut point,
and everything past it — the old extension plus any trailing separators or a trailing
.segment — is dropped.Two behavior changes, both toward
std::pathparity:a.bc/+z→a.z,foo.txt/.//+z→foo.z..:foo.+""→foo(previously left asfoo.).Both
PathBufandUtf8PathBufare fixed, which coversPath::with_extension,Utf8Path::with_extension, and theTyped*wrappers since they all delegate here.Verification
Every expectation in the new tests was checked against
std::path::Path::with_extensionon the same input first, and the reproduction from the issue now matches std exactly:
cargo test --all-featurespasses (202 unit tests, 369 doctests);cargo fmt --checkis clean;
cargo clippyreports only pre-existing findings in untouched files(
common/non_utf8/iter.rs,unix/constants.rs) from a newer clippy than CI pins.Note
src/common/utf8/pathbuf.rshad a#[cfg(all(test, feature = "serde"))] mod testsholding one test; it is merged into a single
#[cfg(test)] mod testswith the serdetest gated individually, so the new tests run without the
serdefeature.https://claude.ai/code/session_01A5uCQTmXn119ATyfP27hfe