Skip to content

fix: quote path variables in write_source_file shell scripts#1239

Merged
fmeum merged 3 commits intobazel-contrib:mainfrom
jfjonsson:fix-write-source-file-quotes
Feb 12, 2026
Merged

fix: quote path variables in write_source_file shell scripts#1239
fmeum merged 3 commits intobazel-contrib:mainfrom
jfjonsson:fix-write-source-file-quotes

Conversation

@jfjonsson
Copy link
Copy Markdown
Contributor

Summary

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=$current_working_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="$current_working_dir/path/to/(folder)/file.txt"
out="path/to/(folder)/file.txt"

Changes

  • lib/private/write_source_file.bzl: Quote path variable assignments
  • 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

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.
@aspect-workflows
Copy link
Copy Markdown

aspect-workflows bot commented Feb 4, 2026

Bazel 8 (Test)

2 test targets passed

Targets
//lib/tests/copy_to_directory:case_22_test [k8-fastbuild]                    61ms
//lib/tests/copy_to_directory_bin_action:test [k8-fastbuild]                 61ms

Total test execution time was 122ms. 135 tests (98.5%) were fully cached saving 16s.


Bazel 9 (Test)

2 test targets passed

Targets
//lib/tests/copy_to_directory:case_22_test [k8-fastbuild]                    96ms
//lib/tests/copy_to_directory_bin_action:test [k8-fastbuild]                 64ms

Total test execution time was 160ms. 135 tests (98.5%) were fully cached saving 18s.


Bazel 7 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 24ms.


Bazel 8 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 30ms.


Bazel 9 (Test)

e2e/api_entries

All tests were cache hits

1 test (100.0%) was fully cached saving 50ms.


Bazel 7 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Bazel 8 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 26ms.


Bazel 9 (Test)

e2e/copy_action

All tests were cache hits

1 test (100.0%) was fully cached saving 32ms.


Bazel 7 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 297ms.


Bazel 8 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 286ms.


Bazel 9 (Test)

e2e/copy_to_directory

All tests were cache hits

6 tests (100.0%) were fully cached saving 349ms.


Bazel 7 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 247ms.


Bazel 8 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 216ms.


Bazel 9 (Test)

e2e/coreutils

All tests were cache hits

4 tests (100.0%) were fully cached saving 198ms.


Bazel 7 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 31ms.


Bazel 8 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 26ms.


Bazel 9 (Test)

e2e/external_copy_to_directory

All tests were cache hits

1 test (100.0%) was fully cached saving 32ms.


Bazel 7 (Test)

e2e/smoke

All tests were cache hits

4 tests (100.0%) were fully cached saving 611ms.


Bazel 8 (Test)

e2e/smoke

All tests were cache hits

4 tests (100.0%) were fully cached saving 508ms.


Bazel 9 (Test)

e2e/smoke

All tests were cache hits

4 tests (100.0%) were fully cached saving 618ms.


Bazel 7 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 39ms.


Bazel 8 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 33ms.


Bazel 9 (Test)

e2e/write_source_files

All tests were cache hits

1 test (100.0%) was fully cached saving 40ms.

@fmeum fmeum enabled auto-merge (squash) February 4, 2026 10:13
auto-merge was automatically disabled February 4, 2026 10:35

Head branch was pushed to by a user without write access

@jfjonsson jfjonsson requested a review from fmeum February 4, 2026 10:50
@fmeum fmeum enabled auto-merge (squash) February 4, 2026 12:01
@fmeum
Copy link
Copy Markdown
Member

fmeum commented Feb 4, 2026

Windows CI still fails.

auto-merge was automatically disabled February 4, 2026 13:41

Head branch was pushed to by a user without write access

@jfjonsson
Copy link
Copy Markdown
Contributor Author

@fmeum sorry for the spam 😅
I didn't find a way to get the windows test log output in the github action

//lib/tests/write_source_files:special_chars_in_path_test                FAILED in 1.4s
  D:/_bazel/execroot/_main/bazel-out/x64_windows-fastbuild/testlogs/lib/tests/write_source_files/special_chars_in_path_test/test.log

But I think I have found all the places where we needed quotes.

@jfjonsson jfjonsson requested a review from fmeum February 4, 2026 13:57
@jfjonsson
Copy link
Copy Markdown
Contributor Author

@fmeum Anything else I need to do before we could merge this?

@fmeum fmeum merged commit 709790d into bazel-contrib:main Feb 12, 2026
20 checks passed
fmeum pushed a commit that referenced this pull request Mar 12, 2026
## 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
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