Skip to content

Commit 68d2323

Browse files
thymikeeclaude
andcommitted
fix: quote sh -c script in adb shell to prevent argument splitting
adb shell concatenates all arguments with spaces into a single string for the remote shell. Without quoting, the && in the mkdir/cat script was interpreted as a command separator, causing mkdir to run with no arguments ("mkdir: Needs 1 argument"). Wrapping the script in single quotes ensures the remote device shell passes the entire command as one argument to sh -c. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c3fb690 commit 68d2323

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/daemon/__tests__/runtime-hints.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ test('applyRuntimeHintsToApp writes React Native Android dev prefs', async () =>
208208
const stdinPayload = await fs.readFile(stdinFilePath, 'utf8');
209209
assert.match(loggedArgs, /shell run-as com\.example\.demo cat shared_prefs\/ReactNativeDevPrefs\.xml/);
210210
assert.match(loggedArgs, /shell run-as com\.example\.demo sh -c/);
211-
assert.equal(script, 'mkdir -p shared_prefs && cat > shared_prefs/ReactNativeDevPrefs.xml');
211+
assert.equal(script, "'mkdir -p shared_prefs && cat > shared_prefs/ReactNativeDevPrefs.xml'");
212212
assert.match(stdinPayload, /<string name="keep">value<\/string>/);
213213
assert.match(stdinPayload, /<string name="debug_http_host">10\.0\.0\.10:8082<\/string>/);
214214
assert.match(stdinPayload, /<boolean name="dev_server_https" value="true" \/>/);

src/daemon/runtime-hints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async function writeAndroidDevPrefs(device: DeviceInfo, packageName: string, xml
150150
}
151151

152152
const script = `mkdir -p shared_prefs && cat > ${ANDROID_DEV_PREFS_PATH}`;
153-
const writeArgs = adbArgs(device, ['shell', 'run-as', packageName, 'sh', '-c', script]);
153+
const writeArgs = adbArgs(device, ['shell', 'run-as', packageName, 'sh', '-c', `'${script}'`]);
154154
try {
155155
await runCmd('adb', writeArgs, { stdin: xml.trimEnd() });
156156
} catch (error) {

0 commit comments

Comments
 (0)