Repository navigation
feat: inspect and decode underscore-hex and percent escaped text - #13
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two subcommands for Korean text that arrives as escaped UTF-8 bytes in file names and URLs:
CLI compatibility
inspectanddecodeare subcommands only as the first argument. Anything else is unchanged:hanfix -- inspectstill converts the word, and the shell functions callhanfix --to en -- $last, sohfand its Korean twin never reach the new code.
tests/cli.rscovers both, plushanfix ㅑㅜ넫ㅊㅅ→inspect.The only way an existing call changes is a bare
hanfix inspect/hanfix decodemeant as English keys toconvert into Hangul;
hanfix -- inspectdoes that now.Contract (tested)
_+ two upper-case hex digits, bytes 0x80-0xFF only.backup_2026_10_29,hello_bed,hello_worldand the first_ofreport__ED_8A_B8.pdfare kept;__is never a space._XXstays text and scanning goes on:
IMG_8123.JPG,DSC_9001.JPG,test_99.txtunchanged with exit 0,_ED_8A_B8_99.txt->트_99.txt,IMG_8123__ED_8A_B8.jpg->IMG_8123_트.jpg. Inside a character everyescape is taken, so
_ED_8A(incomplete),_ED_C3_A9and_DB_backup(_DBis a lead byte) still fail.Percent is unchanged: every
%XXis an escape.--typegiven twice is a usage error.%XX, any byte, either case.%without two hex digits is text (100% done,%GG).+is kept.decodeexits 1,writes nothing to stdout and one
hanfix: error: ...line to stderr. No U+FFFD substitution. The wholetext is checked before anything is printed.
decodeprints it unchanged, exit 0.inspectexits 0 on any text (plain, invalid, mixed);valid/ambiguous(both kinds present) /invalid, with a rule-based reason, no confidence numbers.keeps its lossy read.
--type, unknown option) exit 2, as before.Files
src/encoding.rs: detection, validation and decoding as pure functions with unit tests; no new crates.src/main.rs: subcommand dispatch at the top ofrun(), help and usage text,read_stdin()shared withthe existing path.
usage_erroruseseprintln!(same output) socargo clippy -- -D warningspasses.tests/cli.rs: runs the built binary: stdout/stderr/exit contract, stdin, usage errors, subcommand wordsas text, existing conversions.
README.md,README.ko.md: new "Decode escaped Korean text" section, usage,--type, exit status, and aPowerShell
Rename-Decodedfunction that previewsold -> newby default and renames only with-Apply, skipping names that fail to decode, do not change, are not valid file names, or would overwrite.tests/shells.ps1: extracts that README block, checks the Korean README has the same code, and runs iton a temp folder (preview changes nothing;
-Applyrenames only the decodable, free name).Rename-Decodedfirst probeshanfix decode --type percent -- %41and throwshanfix too old: update with hanfix --updateunless it printsA: hanfix 0.2.7 and older readdecode ...as text and exit 0, so without the probe the example would rename every file.tests/shells.ps1checks this with a stand-in for the old binary (a function callinghanfix -- @args); nothing is renamed.inspectaddsNote: lower-case _xx is not treated as an escapefor runs such as_ed_8a_b8.Rename-Decodedalso skips results that are more than one line or contain control characters (no CR to LFrewrite), end in a dot or space (Windows would drop them), or are a Windows device name; it collects every
name in the folder and every name planned in the run, ignoring case, so the preview lists exactly what
-Applydoes. Tested intests/shells.ps1(percent folder: preview equals apply), also run in WindowsPowerShell 5.1.
Version 0.2.8.
Not in this PR: mojibake (planned next) and the release.
local-ci: 7504d53 |
cargo test --release --locked(10 unit + 7 CLI pass),cargo clippy --all-targets --locked -- -D warningsclean,pwsh tests/shells.ps1with this build first on PATH (3 ok), README example in Windows PowerShell 5.1 (preview correct) on Windows | not run:tests/shells.sh(bash/zsh/fish, Linux only; init scripts untouched), macOS, Termux