Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/common/yok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ export class Yok extends Injector implements IInjector {
* runtime-traced via reportDeprecation.
*/
public get dynamicCallRegex(): RegExp {
return /#{([^.]+)\.([^}]+?)(\((.+)\))*}/;
return /#{([^.]+)\.([^}]+?)(\((.+)\))?}/;
}

/**
Expand Down
28 changes: 15 additions & 13 deletions lib/services/cocoapods-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,9 @@ end`.trim();

extensionsPodfile.forEach(({ targetName, podfilePath }) => {
// Remove the data between #Begin Podfile and #EndPodfile
const regExpToRemove = new RegExp(
`${this.getExtensionPodfileHeader(
podfilePath,
targetName,
)}[\\s\\S]*?${this.getExtensionPodfileEnd()}`,
"mg",
const regExpToRemove = this.getPodfileSectionRegExp(
this.getExtensionPodfileHeader(podfilePath, targetName),
this.getExtensionPodfileEnd(),
);
projectPodFileContent = projectPodFileContent.replace(regExpToRemove, "");

Expand Down Expand Up @@ -448,11 +445,9 @@ end`.trim();
this.getProjectPodfilePath(projectRoot),
);
// Remove the data between #Begin Podfile and #EndPodfile
const regExpToRemove = new RegExp(
`${this.getPluginPodfileHeader(
podfilePath,
)}[\\s\\S]*?${this.getPluginPodfileEnd()}`,
"mg",
const regExpToRemove = this.getPodfileSectionRegExp(
this.getPluginPodfileHeader(podfilePath),
this.getPluginPodfileEnd(),
);
projectPodFileContent = projectPodFileContent.replace(regExpToRemove, "");
projectPodFileContent = this.removePostInstallHook(
Expand Down Expand Up @@ -655,11 +650,18 @@ end`.trim();
}

private getPluginPodfileHeader(pluginPodFilePath: string): string {
// escape special + from the podfile path (pnpm)
pluginPodFilePath = pluginPodFilePath.replace(/\+/g, "\\+");
return `# Begin Podfile - ${pluginPodFilePath}`;
}

private getPodfileSectionRegExp(header: string, end: string): RegExp {
// Podfiles written by older CLI versions have "+" in the header path escaped as "\+".
const headerPattern = header
.split("+")
.map((part) => regExpEscape(part))
.join("\\\\?\\+");
return new RegExp(`${headerPattern}[\\s\\S]*?${regExpEscape(end)}`, "mg");
}

private getPluginPodfileEnd(): string {
return `# End Podfile${EOL}`;
}
Expand Down
60 changes: 60 additions & 0 deletions test/cocoapods-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,66 @@ end`,
);
});
});

describe("when the plugin path contains regular expression characters", () => {
const pnpmPluginData: any = {
name: "plugin1",
pluginPlatformsFolderPath: () =>
"node_modules/.pnpm/plugin1@1.0.0_a+b(peer@2.0.0)/pluginPlatformsFolderPath",
};

const projectPodfileWithHeader = (headerPath: string) => `use_frameworks!

target "projectName" do
# Begin Podfile - ${headerPath}

pod 'GoogleAnalytics', '~> 3.1'

# End Podfile

end`;

it("removes the Podfile section added for the plugin", async () => {
const pluginPodfilePath =
cocoapodsService.getPluginPodfilePath(pnpmPluginData);
mockFileSystem(testInjector, "pod 'GoogleAnalytics', '~> 3.1'");
await cocoapodsService.applyPodfileToProject(
pnpmPluginData.name,
pluginPodfilePath,
mockProjectData,
mockPlatformData,
);
assert.include(newPodfileContent, pluginPodfilePath);

cocoapodsService.removePodfileFromProject(
pnpmPluginData.name,
pluginPodfilePath,
mockProjectData,
nativeProjectPath,
);

assert.isNull(newPodfileContent);
});

it("removes a Podfile section whose header has + escaped", async () => {
const pluginPodfilePath =
cocoapodsService.getPluginPodfilePath(pnpmPluginData);
mockFileSystem(
testInjector,
"",
projectPodfileWithHeader(pluginPodfilePath.split("+").join("\\+")),
);

cocoapodsService.removePodfileFromProject(
pnpmPluginData.name,
pluginPodfilePath,
mockProjectData,
nativeProjectPath,
);

assert.isNull(newPodfileContent);
});
});
});

describe("executePodInstall", () => {
Expand Down
Loading