Skip to content

Fix shell command handling for paths with spaces and metacharacters - #22

Open
Gustavo-Harnisch wants to merge 1 commit into
HamzaHassanain:masterfrom
Gustavo-Harnisch:fix/shell-safe-paths
Open

Fix shell command handling for paths with spaces and metacharacters#22
Gustavo-Harnisch wants to merge 1 commit into
HamzaHassanain:masterfrom
Gustavo-Harnisch:fix/shell-safe-paths

Conversation

@Gustavo-Harnisch

Copy link
Copy Markdown

Summary

Fix shell command handling when Polyman projects or source files are located in paths containing spaces or shell metacharacters.

Problem

Polyman constructed shell commands by interpolating paths and arguments without quoting them.

For example, a project located at:

~/ALEJANDRIA/3)Ejercicios icpc/UCM Grupo /2026/2do Torneo/suma-simple

could fail with:

/bin/sh: 1: Syntax error: ")" unexpected

The shell interpreted characters such as spaces, parentheses, and apostrophes before the arguments reached the compiler or executable.

Changes

  • Add a centralized quoteShellArgument helper.
  • Quote C++ compiler input, output, and include paths.
  • Quote Java compiler paths.
  • Quote C++, Java, Python, and JavaScript runtime paths.
  • Quote standard checker paths.
  • Quote generator and checker arguments.
  • Quote input and output redirection paths.
  • Add the problem root as an include directory so sources inside subdirectories can include the root-level testlib.h.
  • Use end-anchored extension removal for C++ source paths.

Tests

Added regression coverage for:

  • paths containing spaces and parentheses;
  • POSIX paths containing apostrophes;
  • C++ and Java compilation commands;
  • C++, Java, Python, and JavaScript execution commands;
  • standard checker execution;
  • generator and checker arguments;
  • input and output redirection;
  • a POSIX integration test that compiles and executes C++ inside a temporary path containing spaces, ), and an apostrophe.

Validation

  • npm run format:check
  • npm run lint
  • npm run build
  • npm test -- --run

Result:

21 test files passed
760 tests passed

The original C++ reproduction now compiles and runs successfully.

Platform note

The POSIX behavior is covered by unit and integration tests. The Windows quoting branch was reviewed statically but has not yet been exercised in a Windows environment.

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