apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.15k stars 987 forks source link

Podfile generation fails when the project name includes apostrophes and multiple Pods are required #1108

Closed schlusslicht closed 2 years ago

schlusslicht commented 3 years ago

First of all, let me thank You for all Your awesome work on this project! Furthermore, I would have issued a pull request, if I were sure, I had the appropriate fix for this issue. But as it regards regex-matching, I think my (local) quickfix would not be up to Your standards.

Issue Type

Description

The cordova-ios Podfile generation fails, when multiple Pods are required for installation and the PROJECT_NAME includes apostrophes, due to the declarationsPostRE not matching against the escaped PROJECT_NAME.

Information

Command or Code

  1. in the config.xml of Your project declare <name>Rock'n'Roll</name> (any name with one or more apostrophes)
  2. run cordova platform add ios on the respective project, that contains one or more apostrophes in its name
  3. the declarationsPostRE regex does not match (the line gets escaped to target 'Rock\'n\'Roll' do)
  4. the resulting Podfile contains multiple target 'Rock\'n\'Roll' do declarations which triggers
  5. the spawned command pod install --verbose to fail with The target is declared multiple times

Quickfix

Edit the declarationsPostRE:

diff --git a/Podfile.js b/Podfile.js
index f167297..5daf8bc 100644
--- a/Podfile.js
+++ b/Podfile.js
@@ -78,7 +78,7 @@ Podfile.prototype.__parseForDeclarations = function (text) {

     // getting lines between "platform :ios, '11.0'"" and "target 'HelloCordova'" do
     const declarationsPreRE = new RegExp('platform :ios,\\s+\'[^\']+\'');
-    const declarationsPostRE = new RegExp('target\\s+\'[^\']+\'\\s+do');
+    const declarationsPostRE = new RegExp('target\\s+\'.+?\'\\s+do');
     const declarationRE = new RegExp('^\\s*[^#]');

     return arr.reduce((acc, line) => {

Environment, Platform, Device

I think this issue is not tied to any specific environment/device. For my stack, see below.

Version information

Operating System

MacOS X Catalina 10.15.7 (Darwin Kernel 19.6.0)

IDE

Xcode 12.1 (12A7403)

node/npm

node 14.16.0 npm 6.14.11

package.json (relevant entries)

"cordova": "10.0.0" "cordova-ios": "6.2.0" "cordova-plugin-firebase-analytics": "5.0.0" "cordova-plugin-firebase-messaging": "5.0.1"

(Both plugins require a pod to be installed.)

Checklist

schlusslicht commented 2 years ago

Closed due to inactivity.