Fix iOS Podfile pod injection corrupting START/END markers#118
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the 3.3.0 regression where
native:run(iOS) fails atpod installwith a Ruby syntax error:The shipped iOS Podfile template (
resources/xcode/Podfile) wraps the injection site in a paired marker block insidedef shared_pods:addPodDependencies()was checkingstr_contains($podfile, '# NATIVEPHP_PLUGIN_PODS')and thenstr_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/_ENDsuffixes hanging off the last pod line — exactly the broken Podfile reported.Fix
START…ENDblock with anms-mode regex and replace the whole block (preserving the markers) viapreg_replace_callback. The callback bypasses backreference parsing in the replacement string, so pod names with$or\cannot mangle the output. Idempotent on re-run.def shared_pods, so both theNativePHPandNativePHP-simulatortargets pick them up — preserving the template's intent.# NATIVEPHP_PLUGIN_PODSmarker (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
nativephp/mobile-firebase) and runnative:install --force→npm run build→native:runpod installsucceeds and the generatednativephp/ios/Podfilehas pods between the START/END markers, insidedef shared_podsnative:runa second time does not duplicate or further mutate the marker block (idempotency)🤖 Generated with Claude Code