fix(ios): guard against non-string imageURI in createUIImageFromURI#11144
Open
xieweilyg wants to merge 1 commit intoNativeScript:mainfrom
Open
fix(ios): guard against non-string imageURI in createUIImageFromURI#11144xieweilyg wants to merge 1 commit intoNativeScript:mainfrom
xieweilyg wants to merge 1 commit 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.
|
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.
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