Skip to content

Fix iOS Podfile pod injection corrupting START/END markers#118

Merged
shanerbaner82 merged 1 commit into
mainfrom
fix/ios-podfile-plugin-pod-injection
May 8, 2026
Merged

Fix iOS Podfile pod injection corrupting START/END markers#118
shanerbaner82 merged 1 commit into
mainfrom
fix/ios-podfile-plugin-pod-injection

Conversation

@shanerbaner82
Copy link
Copy Markdown
Contributor

Summary

Fixes the 3.3.0 regression where native:run (iOS) fails at pod install with a Ruby syntax error:

pod 'FirebaseMessaging', '~> 12.6.0'_START
...
pod 'FirebaseMessaging', '~> 12.6.0'_END

The shipped iOS Podfile template (resources/xcode/Podfile) wraps the injection site in a paired marker block inside def shared_pods:

  # NATIVEPHP_PLUGIN_PODS_START
  # NATIVEPHP_PLUGIN_PODS_END

addPodDependencies() was checking str_contains($podfile, '# NATIVEPHP_PLUGIN_PODS') and then str_replace('# NATIVEPHP_PLUGIN_PODS', …). That shared prefix matches both marker lines, so str_replace appends the generated pod lines onto each marker, leaving the literal _START / _END suffixes hanging off the last pod line — exactly the broken Podfile reported.

Fix

  • Detect the full START…END block with an ms-mode regex and replace the whole block (preserving the markers) via preg_replace_callback. The callback bypasses backreference parsing in the replacement string, so pod names with $ or \ cannot mangle the output. Idempotent on re-run.
  • Pods stay inside def shared_pods, so both the NativePHP and NativePHP-simulator targets pick them up — preserving the template's intent.
  • A second branch preserves backwards compatibility with the legacy single # NATIVEPHP_PLUGIN_PODS marker (with a \b(?!_) guard so it doesn't re-match the new paired markers).
  • createPodfile() now emits the paired-marker template so freshly created Podfiles take the canonical injection path.

Test plan

  • Apply this patch on a 3.3.0 app with iOS plugins (e.g. nativephp/mobile-firebase) and run native:install --forcenpm run buildnative:run
  • Confirm pod install succeeds and the generated nativephp/ios/Podfile has pods between the START/END markers, inside def shared_pods
  • Confirm running native:run a second time does not duplicate or further mutate the marker block (idempotency)
  • Confirm an app with no iOS plugins still produces a valid Podfile (markers preserved, no pods between them)

🤖 Generated with Claude Code

Symptom (3.3.0 regression seen in the wild): pod install fails with a Ruby
syntax error like:

    pod 'FirebaseMessaging', '~> 12.6.0'_START
    ...
    pod 'FirebaseMessaging', '~> 12.6.0'_END

The shipped Podfile template (resources/xcode/Podfile) wraps the injection
site in a paired marker block inside `def shared_pods`:

    # NATIVEPHP_PLUGIN_PODS_START
    # NATIVEPHP_PLUGIN_PODS_END

addPodDependencies() was checking `str_contains($podfile,
'# NATIVEPHP_PLUGIN_PODS')` and then `str_replace('# NATIVEPHP_PLUGIN_PODS',
…)`. That prefix matches BOTH marker lines, so str_replace appends the
generated pod lines onto each marker, leaving the literal `_START` / `_END`
suffixes attached to the last pod line — the broken Podfile shown above.

Fix: detect the full START…END block with an `ms`-mode regex and replace
the whole block (preserving the markers) via preg_replace_callback. The
callback bypasses backreference parsing in the replacement string, so pod
names containing `$` or `\` cannot mangle the output. Idempotent on re-run.

Behavioural notes:
- The block stays inside `def shared_pods`, so pods are picked up by both
  the `NativePHP` and `NativePHP-simulator` targets — same as the prior
  intent of the template.
- A second arm preserves backwards compatibility with the legacy single
  `# NATIVEPHP_PLUGIN_PODS` marker (used by createPodfile() previously and
  in any user-generated Podfiles still in the wild). The `\b(?!_)` guard
  prevents it from re-matching the new paired markers.
- createPodfile() now emits the paired-marker template so freshly created
  Podfiles take the canonical injection path on subsequent runs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@shanerbaner82 shanerbaner82 merged commit d7f8561 into main May 8, 2026
0 of 5 checks passed
@shanerbaner82 shanerbaner82 deleted the fix/ios-podfile-plugin-pod-injection branch May 8, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant