Skip to content

fix(2.x): quote path variables in write_source_file#1242

Merged
fmeum merged 2 commits intobazel-contrib:2.xfrom
jfjonsson:fix-v2-write-source-file-quotes
Mar 12, 2026
Merged

fix(2.x): quote path variables in write_source_file#1242
fmeum merged 2 commits intobazel-contrib:2.xfrom
jfjonsson:fix-v2-write-source-file-quotes

Conversation

@jfjonsson
Copy link
Contributor

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:

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:

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

  • New test special_chars_in_path_test passes
  • All existing write_source_files tests pass

@jfjonsson
Copy link
Contributor Author

@alexeagle I don't have permission to assign reviewers, any chance you could have a look at this?

@jfjonsson
Copy link
Contributor Author

@fmeum any chance you can take a look at this?

@jfjonsson
Copy link
Contributor Author

@fmeum can we restart the checks?

@fmeum fmeum merged commit 8d46253 into bazel-contrib:2.x Mar 12, 2026
97 of 305 checks passed
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.

2 participants