Skip to content

Halt on control characters during renaming to close #826 - #827

Merged
mathiasrw merged 5 commits into
mainfrom
fix/826
Oct 23, 2026
Merged

mathiasrw merged 5 commits into
mainfrom
fix/826

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #826

Stacked on #812.

Change

--rename and --rename-path remove control characters from the new name: the characters below space in ASCII (0x00 to 0x1F, like the line break, the tab and the null byte) and DEL (0x7F). Windows does not allow them in a name, and on Linux and macOS they break scripts and ls.

The common case is the line break at the end of a replacement file:

> printf 'b\n' > name.txt; touch a.md
> rexreplace '^a' name.txt a.md --rename --replacement-file
b.md

Before, the file got the name b, a line break, and .md. --verbose tells when characters were removed. The help and the README say so too.

Tests

yarn test-ci passes: the demo on Node and Bun, and 1033 Bun tests. test/fix/826.test.js is new, and fails without the fix.

After the review of 24 October

  • Only what the replacement puts in is cleaned, so a file the pattern does not change keeps its name, and a folder with a control character keeps it with --rename-path. Before, rr zzz yyy '*.md' --rename renamed a<tab>b.md to ab.md.
  • A new name that is empty, . or .. is a clash (exit code 3), like when all that was left were control characters.
  • The C1 range (U+0080 to U+009F, like NEL) and the line and paragraph separators are removed too.
  • The help of --rename-path says so too.

After the review of 24 October

Closes #848
Closes #843

The removal of control characters is replaced by a clash, as decided in #848. Nothing is cleaned any more, so the edge cases of cleaning are gone too, like --js code that gives the old name back and still loses a tab.

  • With --rename and --rename-path, a path with a character below space (0x00 to 0x1F, like a line break or a tab) is a clash: the old or the new name of any file in the run, also when the pattern would not change it. No file is renamed, and the exit code is 3. With --replacement-file the message says to use --trim-file for the line break at the end of a file.
  • A new name of only dots and spaces (like an empty name, . or ..), or one that ends with a space or a dot, is a clash too (Fix the checks of new names in --rename: folders, only dots and spaces, and a space or dot at the end #843). Windows does not allow the last two. A name that starts with a dot, like .env, is fine.
  • The new name is checked before it is joined with its folder, so a file in a folder is caught too.
  • A file with a name that can not be made gives one message, and is left out of the other checks.

After the review of 24 October

The --rename help and README now say: "The process will halt before renaming begins if old or new names contain ASCII control characters, end on a space or a dot, or consist only of spaces and dots."

Follow-up

  • DEL (127) is blocked too, so the help sentence on "ASCII control characters" is true. The message is now "Names can not have control characters, like a line break or a tab."

@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 13:05
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 13:10
@mathiasrw
mathiasrw added this pull request to stack #842 October 23, 2026 13:57
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 14:14
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 14:17
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 14:45
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 14:47
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 15:03
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 15:08
@mathiasrw
mathiasrw force-pushed the fix/826 branch 2 times, most recently from 228bd3a to 6405fdb Compare October 23, 2026 15:53
Base automatically changed from fix/790 to main October 23, 2026 15:54
@mathiasrw mathiasrw changed the title Remove control characters from new names of --rename to close #826 Halt on control characters during renaming to close #826 Oct 23, 2026
@mathiasrw
mathiasrw merged commit 0e506d4 into main Oct 23, 2026
6 of 7 checks passed
@mathiasrw
mathiasrw deleted the fix/826 branch October 23, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant