fix(ios): guard against non-string imageURI in createUIImageFromURI#11144
fix(ios): guard against non-string imageURI in createUIImageFromURI#11144xieweilyg wants to merge 2 commits intoNativeScript:mainfrom
Conversation
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: david.xie.
|
There was a problem hiding this comment.
Pull request overview
Fixes an iOS crash in @nativescript/core background rendering when the CSS background shorthand supplies a non-string value into createUIImageFromURI, causing .match() to throw at runtime.
Changes:
- Add a runtime type guard in
createUIImageFromURIto ensureimageURIis a string before calling.match(). - Early-return via
callback(null)whenimageURIis not a string so the background-color pipeline can continue.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: david.xie.
|
|
View your CI Pipeline Execution ↗ for commit ca54e54
☁️ Nx Cloud last updated this comment at |
|
Thank you @xieweilyg , regarding the CLA... What is likely happening and what you can check: If needed, amend the commit author: Force-push: |
Title:
fix(ios): guard against non-string imageURI in createUIImageFromURI
Body:
Summary
When the CSS shorthand property background is used with a plain color value (e.g. background: #1A1A1A), the imageURI parameter passed to createUIImageFromURI in background.ios.ts can be a non-string
type (such as a Color object). This causes imageURI.match(uriPattern) to throw a TypeError at runtime, crashing the application on iOS.
Root Cause
The background CSS shorthand is parsed into multiple sub-properties (background-color, background-image, etc.). In certain cases, a Color object rather than a string is passed through as the imageURI
argument. The existing code assumes imageURI is always a string when truthy, and calls .match() on it directly without a type check.
Fix
Added a typeof imageURI !== 'string' guard before the .match() call. When imageURI is not a string, the function invokes the callback with null and returns early, allowing the rest of the background
rendering pipeline (e.g. background-color) to proceed normally.
if (imageURI) {
if (typeof imageURI !== 'string') {
callback(null);
return;
}
const match = imageURI.match(uriPattern);
// ...
}
How to Reproduce
ActionBar {
background: #1A1A1A;
}
Workaround (before this fix): Replace background with background-color to avoid triggering createUIImageFromURI entirely.
Affected
@nativescript/core