Skip to content

[TarFile]: normalize also concatenated paths (#1072) - #1073

Open
grrtrr wants to merge 7 commits into
bazelbuild:mainfrom
grrtrr:issue_1072
Open

grrtrr wants to merge 7 commits into
bazelbuild:mainfrom
grrtrr:issue_1072

Conversation

@grrtrr

@grrtrr grrtrr commented Jul 11, 2026

Copy link
Copy Markdown

The result of normalize_path() may be a non-normalized path, containing e.g. ../, as a result of prepending self.directory.

Avoid the problem by using normpath() on the result. Resolves #1072.

The result of `normalize_path()` may be a non-normalized path,
containing e.g. `../`, as a result of prepending `self.directory`.

Avoid the problem by using `normpath()` on the result.
Resolves bazelbuild#1072.
@grrtrr
grrtrr requested review from aiuto and cgrindel as code owners July 11, 2026 15:36
@aiuto

aiuto commented Aug 18, 2026 •

Copy link
Copy Markdown
Collaborator

This makes one of the tar tests fail AssertionError: 'loremipsum.txt' != './loremipsum.txt'
So there is some subtle different behavior. We need to understand how that might change existing workflows.

What if you just normalized --directory?

@grrtrr

grrtrr commented Aug 18, 2026

Copy link
Copy Markdown
Author

This makes one of the tar tests fail AssertionError: 'loremipsum.txt' != './loremipsum.txt' So there is some subtle different behavior. We need to understand how that might change existing workflows.

What if you just normalized --directory?

I don't think the test failures are related. Normalizing --directory might work, doing this inside the function seemed to make the most sense, consistent with the earlier call to normpath().

@aiuto

aiuto commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Can you try a merge from head and re-push so we can run with current tests?

@grrtrr

grrtrr commented Oct 6, 2026

Copy link
Copy Markdown
Author

Can you try a merge from head and re-push so we can run with current tests?

Yes, just refreshed.

@tonyaiuto

Copy link
Copy Markdown
Collaborator

I don't understand why you are still getting bazel7 in the tests.
So I patched it in and I see the same failure on my machine

AssertionError: 'loremipsum.txt' != './loremipsum.txt'
- loremipsum.txt
+ ./loremipsum.txt
? ++
 : Value `loremipsum.txt` for key `name` of file loremipsum.txt in archive /private/var/tmp/_bazel_tony/f3f83a225d68142b93b7d515eb69bd02/sandbox/darwin-sandbox/409/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/tests/tar/pkg_tar_test.runfiles/_main/tests/tar/test_tar_leading_dotslash.tar does not match expected value `./loremipsum.txt`

This is going to break people because the expect the leading ./ on their files.
How about if you just solve the one problem and make it
dest = (self.directory + dest).replace("/../", "/")

@grrtrr

grrtrr commented Oct 10, 2026

Copy link
Copy Markdown
Author

@aiuto - apologies, I had messed up the branch by using the 'merge' button.

Also researched (with the help of Claude) what was causing the problem - normpath() strips the leading './', which it should not:

input os.path.normpath
'./loremipsum.txt' 'loremipsum.txt'
'./a/./b' 'a/b'
'./' '.'
'../a' '../a' (leading .. kept)
'./../a' '../a'

Hence updated code to accommodate that. Tests now pass.

This branch has not been deployed

No deployments
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.

[TarFile]: normalize_path does not normalize when --directory is present

4 participants