|
1 | 1 | // 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"; |
3 | 3 | import { |
4 | 4 | chmodSync, |
5 | 5 | mkdirSync, |
@@ -138,8 +138,11 @@ if (extractIndex < 0 || expectIndex < 0 || process.argv[expectIndex + 1] !== "st |
138 | 138 | const key = process.argv[extractIndex + 1]; |
139 | 139 | const file = process.argv[process.argv.length - 1]; |
140 | 140 | 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>")); |
143 | 146 | if (!match) process.exit(1); |
144 | 147 | process.stdout.write(match[1]); |
145 | 148 | `, |
@@ -395,6 +398,37 @@ describe("scripts/ios-validate-app-store-ipa.sh", () => { |
395 | 398 | } |
396 | 399 | }); |
397 | 400 |
|
| 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 | + |
398 | 432 | it("accepts an App Store IPA with appStore mode and production entitlements", async () => { |
399 | 433 | const root = mkdtempSync(path.join(os.tmpdir(), "openclaw-ios-ipa-")); |
400 | 434 | tempDirs.push(root); |
|
0 commit comments