Repository navigation
Conversation
Paths containing spaces, quotes or $(...) no longer break the diff or reach a shell, and Differ no longer crashes when every option is set (compact! returned nil). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Hi Marco, thanks for difftastic-ruby, we use it to render inline diffs of edited texts in our back office.
While profiling it I noticed that
Differ#diff_filesbuilds a single command string and runs it with backticks. When a path contains shell metacharacters, Ruby hands that string to/bin/sh: a file nameda $(touch injected).txtactually runstouch injected, a quote in a filename breaks the command, and aTMPDIRcontaining a space makesdiff_stringsreturnnil. This PR adds a smallDifftastic.capture(*arguments)that runsIO.popen([executable, *arguments], &:read), so arguments go straight todifftwith no shell involved.Difftastic.executeis left untouched for anyone calling it directly.It also fixes a crash I hit along the way:
options.compact!returnsnilwhen nothing was removed, soDiffer.new(color:, context:, background:, syntax_highlight:, tab_width:, width:)with every option set raisedNoMethodError: undefined method 'join' for nil.test/shell_test.rbcovers the three cases (metacharacters in paths, aTMPDIRwith a space, every option set); all three fail onmainand pass here, along with the existing suite. Outputs are byte-identical tomainon 600 random text pairs across inline/side-by-side, color on/off and labels containing$(...), backticks and quotes. Speed is unchanged, since Ruby already skipped the shell for plain Tempfile paths. The actual speed-up for inline diffs is a separate question, in #38.🤖 Generated with Claude Code, but prompted, read, and verified by @czj, a caring human :)