Skip to content

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

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

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

Conversation

@xieweilyg
Copy link
Copy Markdown

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
Copy Markdown

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 protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 createUIImageFromURI to ensure imageURI is a string before calling .match().
  • Early-return via callback(null) when imageURI is 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]>
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 27, 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 protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 27, 2026

View your CI Pipeline Execution ↗ for commit ca54e54

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 44s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-27 22:36:16 UTC

@NathanWalker
Copy link
Copy Markdown
Contributor

NathanWalker commented Mar 27, 2026

Thank you @xieweilyg , regarding the CLA...

What is likely happening and what you can check:

git config user.name
git config user.email

If needed, amend the commit author:

git commit --amend --author="xieweilyg [[email protected]]"

Force-push:

git push --force-with-lease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants