Skip to content

Comments

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

Open
jfjonsson wants to merge 2 commits intobazel-contrib:2.xfrom
jfjonsson:fix-v2-write-source-file-quotes
Open

fix(2.x): quote path variables in write_source_file#1242
jfjonsson wants to merge 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

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