Skip to content

fix(ios): guard against non-string imageURI in createUIImageFromURI#11144

Open
xieweilyg wants to merge 1 commit intoNativeScript:mainfrom
xieweilyg:fix/background-ios-imageuri-type-check
Open

fix(ios): guard against non-string imageURI in createUIImageFromURI#11144
xieweilyg wants to merge 1 commit intoNativeScript:mainfrom
xieweilyg:fix/background-ios-imageuri-type-check

Conversation

@xieweilyg
Copy link

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

  1. Set a background on any view using the CSS shorthand with a plain color:
    ActionBar {
    background: #1A1A1A;
    }
  2. Run on iOS
  3. App crashes with TypeError: imageURI.match is not a function

Workaround (before this fix): Replace background with background-color to avoid triggering createUIImageFromURI entirely.

Affected

@nativescript/core

@cla-bot
Copy link

cla-bot bot commented Mar 24, 2026

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 is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

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