Fix missing .txt extension in proxy output filenames#3
Fix missing .txt extension in proxy output filenames#3MichaelMVS wants to merge 1 commit intoSkillter:masterfrom
Conversation
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.
There was a problem hiding this comment.
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
extto.txtand treatoutput_baseas the base name unless it ends with a recognized extension. - Conditionally apply
os.path.splitextonly for a fixed set of extensions (.txt,.csv,.json,.log).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # 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) |
There was a problem hiding this comment.
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.
| # 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" |
| # 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) |
There was a problem hiding this comment.
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).
|
The bug you claim to fix doesn't exist. Please verify before you open a pull request if you use AI. |
Summary
When
_save_working_proxiesis 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
_save_working_proxiesfile extension logic