Skip to content

Fix --normalize writing to wrong path with multiple files - #702

Closed
bysiber wants to merge 1 commit into
jawah:masterfrom
bysiber:fix/cli-normalize-unicode-path-index
Closed

bysiber wants to merge 1 commit into
jawah:masterfrom
bysiber:fix/cli-normalize-unicode-path-index

Conversation

@bysiber

@bysiber bysiber commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix incorrect file index when writing normalized output for multiple files.

Problem

When normalizing multiple files with normalizer --normalize file1.txt file2.txt, the CLI always references x_[0] (the first result entry) instead of the current file's result:

x_[0].unicode_path = join(dir_path, ".".join(o_))

with open(x_[0].unicode_path, "wb") as fp:
    fp.write(best_guess.output())

For the second file onward, this:

  1. Overwrites the first entry's unicode_path with the current file's output path
  2. Writes the normalized content to a path derived from the wrong entry

Fix

Use x_[-1] to reference the most recently appended result, which is always the current file being processed.

When normalizing multiple files, x_[0].unicode_path was always
used — pointing to the first file's result entry regardless of
which file was being processed. This caused the output path to
be set on the wrong CliDetectionResult and the normalized content
to be written to a path derived from the first file's name.

Use x_[-1] to reference the most recently appended result entry,
which corresponds to the current file being processed.
@bysiber
bysiber requested a review from Ousret as a code owner February 20, 2026 15:21

@Ousret Ousret left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the fix is incomplete/invalid.
I agree something is missing in the case where we pass many files in the CLI.
This need a more careful investigation and proper solution to not confuse current users.

regards,

Ousret added a commit that referenced this pull request Mar 15, 2026
supersede #702

Co-authored-by: Kadir Can Ozden <101993364+bysiber@users.noreply.github.com>
@Ousret Ousret mentioned this pull request Mar 15, 2026
@Ousret

Ousret commented Mar 15, 2026

Copy link
Copy Markdown
Member

Solved in PR #715

regards,

@Ousret Ousret closed this Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants