fix #147 white-space bug in by shellescape-ing all variable substitutions#148
Merged
CRAG666 merged 1 commit intoCRAG666:mainfrom Mar 10, 2026
Merged
fix #147 white-space bug in by shellescape-ing all variable substitutions#148CRAG666 merged 1 commit intoCRAG666:mainfrom
CRAG666 merged 1 commit intoCRAG666:mainfrom
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.
Aims to fix the issue #147
The root cause of the issue lies in the
lua/code_runner/utils.luafile, where, thereplaceVarsfunction substitutes$fileName,$file,$dir, and$fileNameWithoutExtvariables directly into the shell command string without quoting:When any of these values contains a space, the shell tokenises the resulting command incorrectly. The same issue affects the fallback path-append at the bottom of
replaceVarswhen no$varsubstitution is matched.Major changes made
All file path values substituted into shell commands in
replaceVarsare now wrapped withvim.fn.shellescape(). This ensures paths containing spaces (or other shell-special characters) are treated as single arguments by the shell.The issue was resolved by shellescape-ing variables, since functions like
vim.fn.shellescape()is Neovim's built-in shell quoting function. It wraps the value in single quotes and escapes any single quotes within the value.File:
lua/code_runner/code_runner.lua—M.run_codefunction1. Shellescape the bufname passed to
runModeThis is where the path first enters the execution pipeline.
vim.fn.expand("%:t:r")returns the raw filename stem (e.g.my file) with no quoting. The shell then splits it into separate tokens. Wrapping it withvim.fn.shellescape()before it is passed torunModeensures it is treated as a single argument.File:
lua/code_runner/utils.lua—replaceVarsfunction2. Quote
file_infovalues3. Quote
$filesubstitution (rawpathvariable)4. Quote fallback path append
All in all, this fix covers all touch points across both files: the
runModecall incode_runner.lua, and all four substitution points inreplaceVars:$fileNameWithoutExt,$fileName,$file,$dir.