Make StandardizedPath::strip_prefix component-aware#11936
Conversation
`StandardizedPath::strip_prefix` stripped a raw string prefix instead of
matching whole path components. As a result a base like `/repo` was
treated as a prefix of the sibling path `/repository/foo.rs`, returning a
bogus mid-component remainder `Some("sitory/foo.rs")` instead of `None`.
This contradicted the sibling `starts_with`/`ends_with` methods (both
component-aware) and silently broke `LocalOrRemotePath::strip_repo_prefix`
for remote paths: its `Local` arm uses the component-aware
`Path::strip_prefix` and correctly rejects siblings, while its `Remote`
arm went through this method and mis-attributed files in a sibling
directory to the repo.
Gate the strip on the component-aware `starts_with` before slicing. For
two normalized paths a component prefix is also a byte prefix, so the cut
lands on a component boundary. Add regression tests at both the
`StandardizedPath` and `strip_repo_prefix` levels.
|
This PR is not linked to an issue that is marked with Issue-state enforcement details:
To continue, link this PR to a same-repo issue such as Powered by Oz |
There was a problem hiding this comment.
This PR is not linked to an issue that is marked with ready-to-implement.
Issue-state enforcement details:
-
Associated same-repo issues checked: none
-
Required readiness label:
ready-to-implement
To continue, link this PR to a same-repo issue such as Closes #123 in the PR description, and make sure that issue has ready-to-implement.
Powered by Oz
|
/oz-review |
There was a problem hiding this comment.
This PR is not linked to an issue that is marked with ready-to-implement.
Issue-state enforcement details:
-
Associated same-repo issues checked: none
-
Required readiness label:
ready-to-implement
To continue, link this PR to a same-repo issue such as Closes #123 in the PR description, and make sure that issue has ready-to-implement.
Powered by Oz
StandardizedPath::strip_prefix
stripped a raw string prefix instead of matching whole path components. As a result a base like/repowas treated as a prefix of the sibling path/repository/foo.rs, returning a bogus mid-component remainderSome("sitory/foo.rs")instead ofNone`.This contradicted the sibling
starts_with/ends_withmethods (both component-aware) and silently brokeLocalOrRemotePath::strip_repo_prefixfor remote paths: itsLocalarm uses the component-awarePath::strip_prefixand correctly rejects siblings, while itsRemotearm went through this method and mis-attributed files in a sibling directory to the repo.Gate the strip on the component-aware
starts_withbefore slicing. For two normalized paths a component prefix is also a byte prefix, so the cut lands on a component boundary. Add regression tests at both theStandardizedPathandstrip_repo_prefixlevels.solve #11937