Skip to content

Commit 71bc1b3

Browse files
committed
fix(test): make fake plutil metacharacter escaping survive the template hop
1 parent 0af71ab commit 71bc1b3

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

‎test/scripts/ios-validate-app-store-ipa.test.ts‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// iOS IPA validation tests cover the App Store upload gate without real signing assets.
2-
import { execFileSync } from "node:child_process";
2+
import { execFileSync, spawnSync } from "node:child_process";
33
import {
44
chmodSync,
55
mkdirSync,
@@ -138,8 +138,11 @@ if (extractIndex < 0 || expectIndex < 0 || process.argv[expectIndex + 1] !== "st
138138
const key = process.argv[extractIndex + 1];
139139
const file = process.argv[process.argv.length - 1];
140140
const xml = readFileSync(file, "utf8");
141-
const escapedKey = key.replace(/[.*+?^\${}()|[]\\]/g, "\\$&");
142-
const match = xml.match(new RegExp("<key>" + escapedKey + "<\\/key>\\s*<string>([^<]*)<\\/string>"));
141+
// Escapes are doubled for the template-literal -> emitted-file hop: the emitted script
142+
// must contain \\] in the class and \\$& in the replacement, or keys with regex
143+
// metacharacters interpolate unescaped into the RegExp below and stop emulating plutil.
144+
const escapedKey = key.replace(/[.*+?^\${}()|[\\]\\\\]/g, "\\\\$&");
145+
const match = xml.match(new RegExp("<key>" + escapedKey + "</key>\\\\s*<string>([^<]*)</string>"));
143146
if (!match) process.exit(1);
144147
process.stdout.write(match[1]);
145148
`,
@@ -395,6 +398,37 @@ describe("scripts/ios-validate-app-store-ipa.sh", () => {
395398
}
396399
});
397400

401+
it("fake plutil escapes regex-metacharacter keys before matching", () => {
402+
const root = mkdtempSync(path.join(os.tmpdir(), "openclaw-ios-ipa-"));
403+
tempDirs.push(root);
404+
const plutil = path.join(root, "plutil");
405+
writeFakePlutil(plutil);
406+
const plistPath = path.join(root, "meta.plist");
407+
writeFileSync(
408+
plistPath,
409+
"<plist><dict>\n<key>Weird[Key]*</key>\n<string>metavalue</string>\n</dict></plist>",
410+
"utf8",
411+
);
412+
const escaped = spawnSync(
413+
process.execPath,
414+
[plutil, "-extract", "Weird[Key]*", "-expect", "string", plistPath],
415+
{
416+
encoding: "utf8",
417+
},
418+
);
419+
expect(escaped.status).toBe(0);
420+
expect(escaped.stdout).toBe("metavalue");
421+
// An unescaped interpolation would let this key match as a regex; it must miss instead.
422+
const missing = spawnSync(
423+
process.execPath,
424+
[plutil, "-extract", "Weird.Key.*", "-expect", "string", plistPath],
425+
{
426+
encoding: "utf8",
427+
},
428+
);
429+
expect(missing.status).toBe(1);
430+
});
431+
398432
it("accepts an App Store IPA with appStore mode and production entitlements", async () => {
399433
const root = mkdtempSync(path.join(os.tmpdir(), "openclaw-ios-ipa-"));
400434
tempDirs.push(root);

0 commit comments

Comments
 (0)