Skip to content

fix(sed): preserve escaped replacement characters - #252

Open
Voyagerroc-Lab wants to merge 1 commit into
shelljs:mainfrom
Voyagerroc-Lab:fix/sed-replacement-escaping
Open

Voyagerroc-Lab wants to merge 1 commit into
shelljs:mainfrom
Voyagerroc-Lab:fix/sed-replacement-escaping

Conversation

@Voyagerroc-Lab

Copy link
Copy Markdown

shx sed silently corrupts escaped replacement characters. For example, replacing foo with the escaped Windows path C:\\temp\\file.txt produces C:.temp.file.txt and exits successfully. This also affects -i, writing the corrupted path to disk.

Unescape replacement characters in one pass, retaining the escaped character instead of substituting a dot. A single pass also prevents adjacent escaped backslashes and slashes from being interpreted twice.

Regression tests exercise file input without -g, stdin with adjacent escapes, and in-place global replacement. They verify output/file contents, exit status, and stderr. All three fail on unchanged main (3d4e06c49a4f4835b9f9aedc728a71d6b7b06493) and pass with the fix.

Validation on Windows, Node v24.19.0:

  • Invoked src/cli.js as a child process with piped input before and after the fix; confirmed both the Windows path and adjacent-backslash/slash reproductions.
  • npm test: 42 passing, 3 existing platform skips for chmod; posttest ESLint passed.
  • npm run check-node-support: passed.
  • git diff --check: passed.

This fixes literal replacement escaping only. It does not implement Unix sed basic regex syntax or numeric backreferences, and does not close the broader compatibility request #225. Other operating systems and Node versions were not run locally.

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.

1 participant