fix: quote path variables in write_source_file shell scripts#1239
fix: quote path variables in write_source_file shell scripts#1239fmeum merged 3 commits intobazel-contrib:mainfrom
Conversation
Paths containing shell metacharacters (like parentheses) caused syntax errors. Added quotes around variable assignments in the generated shell scripts and included a regression test with parentheses in the path.
|
Head branch was pushed to by a user without write access
|
Windows CI still fails. |
Head branch was pushed to by a user without write access
|
@fmeum sorry for the spam 😅 But I think I have found all the places where we needed quotes. |
|
@fmeum Anything else I need to do before we could merge this? |
## Summary Backport of #1239 to 2.x. Fix `write_source_file` failing with shell syntax errors when paths contain metacharacters like parentheses. ## Problem The generated shell script assigned paths to variables without quoting: ```bash in=$runfiles_dir/path/to/(folder)/file.txt out=path/to/(folder)/file.txt ``` Bash interprets `(` as the start of a subshell, causing: ``` syntax error near unexpected token `(' ``` This breaks builds using Next.js App Router route groups (e.g., `app/(dashboard)/page.tsx`) or any path with parentheses, spaces, or other shell metacharacters. ## Fix Quote the variable assignments: ```bash in="$runfiles_dir/path/to/(folder)/file.txt" out="path/to/(folder)/file.txt" ``` ## Changes - `lib/private/write_source_file.bzl`: Quote path variable assignments in both bash and batch scripts - `lib/tests/write_source_files/write_source_file_test.bzl`: Quote paths in test script generator - Added regression test with parentheses in path (`(route-group)/test.js`) ## Test plan - [x] New test `special_chars_in_path_test` passes - [x] All existing `write_source_files` tests pass

Summary
Fix
write_source_filefailing with shell syntax errors when paths contain metacharacters like parentheses.Problem
The generated shell script assigned paths to variables without quoting:
in=$current_working_dir/path/to/(folder)/file.txt out=path/to/(folder)/file.txtBash interprets
(as the start of a subshell, causing:This breaks builds using Next.js App Router route groups (e.g.,
app/(dashboard)/page.tsx) or any path with parentheses, spaces, or other shell metacharacters.Fix
Quote the variable assignments:
Changes
lib/private/write_source_file.bzl: Quote path variable assignmentslib/tests/write_source_files/write_source_file_test.bzl: Quote paths in test script generator(route-group)/test.js)Test plan
special_chars_in_path_testpasseswrite_source_filestests pass