Skip to content

Fix missing .txt extension in proxy output filenames#3

Closed
MichaelMVS wants to merge 1 commit intoSkillter:masterfrom
MichaelMVS:fix-file-extension-handling
Closed

Fix missing .txt extension in proxy output filenames#3
MichaelMVS wants to merge 1 commit intoSkillter:masterfrom
MichaelMVS:fix-file-extension-handling

Conversation

@MichaelMVS
Copy link
Copy Markdown

Summary

When _save_working_proxies is called with an output_base that has no file extension (e.g. `working-proxies-2026-04-11_03-40-00`), the saved proxy files were being created without the `.txt` extension.

Root Cause

`os.path.splitext("working-proxies-2026-04-11_03-40-00")` returns `("working-proxies-2026-04-11_03-40-00", "")`, giving an empty extension. The old code only set `ext = ".txt"` when `not ext`, but the filenames were then constructed as `{base}-{protocol}{ext}`, resulting in files like `working-proxies-2026-04-11_03-40-00-http` — missing the `.txt` extension.

Fix

Initialize `base = output_base` and `ext = ".txt"` by default, and only use `os.path.splitext` when the output_base ends with a known extension pattern. This ensures files always get the correct extension.

Files Changed

  • CheckProxies.py: Fixed _save_working_proxies file extension logic

When output_base has no extension (e.g. 'working-proxies-2026-04-11_03-40-00'),
os.path.splitext returns (base, '') with empty extension. The old code
only set ext='.txt' if not ext, but base would be 'working-proxies-2026-04-11_03-40-00'
and filenames would be 'working-proxies-2026-04-11_03-40-00-http' (missing .txt).

Fixed by initializing base=output_base and ext='.txt', then only splitting
if the output_base ends with a known extension pattern.
Copilot AI review requested due to automatic review settings April 11, 2026 03:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates _save_working_proxies in CheckProxies.py to ensure generated per-protocol output filenames include a default .txt extension when the user-provided output_base has no extension, aligning proxy output naming with the script’s expected plain-text output format.

Changes:

  • Default ext to .txt and treat output_base as the base name unless it ends with a recognized extension.
  • Conditionally apply os.path.splitext only for a fixed set of extensions (.txt, .csv, .json, .log).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +20 to +25
# Split off the extension (e.g. ".txt") to get the base name
# If the output_base has no extension, we treat the whole thing as the base
base = output_base
ext = ".txt"
if output_base.endswith(('.txt', '.csv', '.json', '.log')):
base, ext = os.path.splitext(output_base)
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

The new allowlist-based endswith(('.txt', '.csv', '.json', '.log')) means user-supplied extensions outside that set (or uppercase variants like .TXT) will be ignored and the code will always append .txt, changing the CLI/API behavior compared to simply honoring whatever extension the user passed. Consider reverting to always using os.path.splitext(output_base) and only defaulting to .txt when the split extension is empty (and optionally treating ext == '.' as “no extension”), rather than restricting to a fixed list.

Suggested change
# Split off the extension (e.g. ".txt") to get the base name
# If the output_base has no extension, we treat the whole thing as the base
base = output_base
ext = ".txt"
if output_base.endswith(('.txt', '.csv', '.json', '.log')):
base, ext = os.path.splitext(output_base)
# Split off the extension (e.g. ".txt") to get the base name.
# If the output_base has no extension, we treat the whole thing as the base
# and default to ".txt". Treat a lone "." as no extension as well.
base, ext = os.path.splitext(output_base)
if not ext or ext == '.':
base = output_base.rstrip('.') if ext == '.' else output_base
ext = ".txt"

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +25
# Split off the extension (e.g. ".txt") to get the base name
# If the output_base has no extension, we treat the whole thing as the base
base = output_base
ext = ".txt"
if output_base.endswith(('.txt', '.csv', '.json', '.log')):
base, ext = os.path.splitext(output_base)
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

PR description says the previous logic set ext = '.txt' when splitext returned an empty extension, but the removed code in this hunk already does exactly that. It would be good to add a minimal repro in the PR description (exact --output value) or adjust the code accordingly, because as-written this change may not address the originally reported case and could be masking a different issue (e.g., an output_base ending with a dot).

Copilot uses AI. Check for mistakes.
@Skillter
Copy link
Copy Markdown
Owner

The bug you claim to fix doesn't exist.

Please verify before you open a pull request if you use AI.

@Skillter Skillter closed this Apr 11, 2026
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.

3 participants