Skip to content

Commit 4808af7

Browse files
committed
fix(ios): preserve whitespace in unrelated linker flags when stripping metadata directive
1 parent 30c8d3d commit 4808af7

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎lib/services/ios/embed-metadata-linker-flag.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,23 @@ export function metadataSectionFlag(metadataFilePath: string): string {
4040
* so unrelated spacing is never rewritten.
4141
*/
4242
function stripMetadataDirectives(entry: string): string {
43-
const without = entry.replace(METADATA_DIRECTIVE, " ");
44-
if (without === entry) {
43+
const directiveWithSurroundingSpace = new RegExp(
44+
`([ \\t]*)${METADATA_DIRECTIVE.source}([ \\t]*)`,
45+
"g",
46+
);
47+
let matched = false;
48+
const without = entry.replace(
49+
directiveWithSurroundingSpace,
50+
(_match, before: string, after: string) => {
51+
matched = true;
52+
return before && after ? " " : "";
53+
},
54+
);
55+
if (!matched) {
4556
return entry;
4657
}
4758

48-
return without.replace(/[ \t]{2,}/g, " ").trim();
59+
return without.trim();
4960
}
5061

5162
/** True when an entry held nothing but the directive once it was removed. */

‎test/ios-project-service.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,24 @@ describe("embed metadata linker flag", () => {
16881688
}
16891689
});
16901690

1691+
it("preserves repeated whitespace in unrelated flag arguments when stripping a directive", async () => {
1692+
const combined = JSON.stringify(
1693+
'-force_load "libs/My Library.a" -sectcreate __DATA __TNSMetadata "../embedHost/metadata-arm64.bin"',
1694+
);
1695+
const { prepare, flagsOfTarget, seedFlags } = setup();
1696+
seedFlags(['"$(inherited)"', combined]);
1697+
1698+
await prepare();
1699+
1700+
for (const flags of flagsOfTarget()) {
1701+
assert.lengthOf(metadataDirectives(flags), 1);
1702+
assert.include(
1703+
flags,
1704+
JSON.stringify('-force_load "libs/My Library.a"'),
1705+
);
1706+
}
1707+
});
1708+
16911709
it("reports a broken host project instead of hiding it at trace level", async () => {
16921710
const logged: any[] = [];
16931711
const testInjector = createTestInjector(

0 commit comments

Comments
 (0)