Skip to content

fix: handle proper tokenization for --extra-params flag#2822

Draft
valeriobelli wants to merge 1 commit into
react-native-community:mainfrom
valeriobelli:handle-proper-tokenization-for-extra-params
Draft

fix: handle proper tokenization for --extra-params flag#2822
valeriobelli wants to merge 1 commit into
react-native-community:mainfrom
valeriobelli:handle-proper-tokenization-for-extra-params

Conversation

@valeriobelli

Copy link
Copy Markdown

Summary

--extra-params was split naively on spaces (val.split(' ')), which broke any argument containing a legitimate space and leaked the quote characters through, e.g.:

  --extra-params='-destination "iOS Simulator" CODE_SIGNING_ALLOWED=NO'
  --extra-params='EXCLUDED_ARCHS="arm64 i386"'

Replace the split with a shared, quote-aware tokenizeCommand utility in cli-tools. It honors single/double quotes, joins adjacent quoted and unquoted segments into one token, and does no shell interpretation; values like OTHER_LDFLAGS=$(inherited) and Windows Gradle paths (C:\keys\app.jks) reach the tool verbatim. Empty/whitespace-only arguments yield no arguments, and an unterminated quote throws a clear error.

Wired into XcodeBuild (buildOptions) and Gradle (buildAndroid, which is also reused by run-android). The Xcode build log now quotes arguments containing whitespace so it stays copy-pasteable.

Additionally, the apple-related buildProject function accounts for this change when printing the generated xcodebuild command, enabling effective copy-and-paste.

Test Plan

Added tests in packages/cli-tools/src/__tests__/tokenizeCommand.test.ts asserting some use cases.

$ jest packages/cli-tools/src/__tests__/tokenize.test.ts
 PASS   unit  packages/cli-tools/src/__tests__/tokenize.test.ts
  tokenize
    ✓ splits space-separated xcodebuild arguments
    ✓ splits space-separated gradle properties
    ✓ keeps a double-quoted xcodebuild destination with spaces in one token
    ✓ keeps a single-quoted destination specifier with spaces in one token
    ✓ strips the surrounding quotes from a quoted path containing a space
    ✓ joins an unquoted build-setting name with its quoted, space-containingvalue
    ✓ collapses extra whitespace (spaces and tabs) between arguments
    ✓ passes xcodebuild build-setting syntax such as $(inherited) through verbatim
    ✓ keeps backslashes literal so Windows gradle paths survive
    ✓ returns an empty array for empty input
    ✓ returns an empty array for whitespace-only input
    ✓ drops a stray empty quoted argument
    ✓ throws on an unterminated double quote
    ✓ throws on an unterminated single quote

Test Suites: 1 passed, 1 total

Checklist

  • Documentation is up to date.
  • Follows commit message convention described in CONTRIBUTING.md.
  • For functional changes, my test plan has linked these CLI changes into a local react-native checkout (instructions).

`--extra-params` was split naively on spaces (`val.split(' ')`), which
broke any argument containing a legitimate space and leaked the quote
characters through, e.g.:

  --extra-params='-destination "iOS Simulator" CODE_SIGNING_ALLOWED=NO'
  --extra-params='EXCLUDED_ARCHS="arm64 i386"'

Replace the split with a shared, quote-aware `tokenize` utility in`
`cli-tools`. It honors single/double quotes, joins adjacent quoted and
unquoted segments into one token, and does no shell interpretation
values like `OTHER_LDFLAGS=$(inherited)` and Windows gradle paths
(`C:\keys\app.jks`) reach the tool verbatim. Empty/whitespace-only arguments
yields no arguments, and an unterminated quote throws a clear error.

Wired into xcodebuild (buildOptions) and gradle (buildAndroid, which is
also reused by run-android). The xcodebuild build log now quotes
arguments containing whitespace so it stays copy-pasteable.

Additionally, the apple-related `buildProject` function accounts for
this change when printing the generated `xcodebuild` command, enabling
effective copy-and-paste.
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