Skip to content

Match hand-typed command targets ignoring case and surrounding spaces - #7226

Merged
TimoPtr merged 4 commits into
home-assistant:mainfrom
markfrancisonly:fix/case-insensitive-command-targets
Jul 21, 2026
Merged

TimoPtr merged 4 commits into
home-assistant:mainfrom
markfrancisonly:fix/case-insensitive-command-targets

Conversation

@markfrancisonly

@markfrancisonly markfrancisonly commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Notification commands carry values the user types by hand, but two of the matchers treated them as if they were machine-generated — matching case-sensitively and keeping surrounding whitespace:

  • UrlUtil.isAbsoluteUrl matched the scheme with a case-sensitive ^https?:// regex. An uppercase HTTPS://… value — in a command_webview/URI, or a notification image/icon/video URL — was therefore treated as relative and resolved against the server base URL instead of used as an absolute URL.
  • FrontendTarget.fromRawPath matched the entityId: prefix case-sensitively and kept surrounding whitespace, so EntityId:light.kitchen opened as a dashboard path instead of the more-info dialog, and a blank value became Path("") rather than the default dashboard.

Both matchers now ignore case; fromRawPath also trims the value and maps a blank path to the default dashboard. Behavior for well-formed values is unchanged. These are the paths exercised by MessagingManager (command_webview, notification media URLs) and the device-controls panel / frontend deep links.

Split out from #7163 per review feedback there, so the navigation change stays focused. The isAbsoluteUrl change was reverted out of #7163; the FrontendTarget.fromRawPath change is byte-identical in both, so whichever merges first the other's hunk merges cleanly — no rebase needed.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Link to pull request in documentation repositories

User Documentation: home-assistant/companion.home-assistant#

Developer Documentation: home-assistant/developers.home-assistant#

Any other notes

isAbsoluteUrl (:common) and fromRawPath (:app) are covered by parameterized/added unit tests including the uppercase-scheme, mixed-case entityId: prefix, blank, and surrounding-whitespace cases. No user-facing UI change, so no screenshots.

Notification commands carry values the user types by hand, but two of the
matchers were case-sensitive and space-sensitive:

- UrlUtil.isAbsoluteUrl matched the scheme with a case-sensitive regex, so
  an uppercase HTTPS:// URL in a command or a notification image was treated
  as relative and resolved against the server base URL instead of used as-is.
- FrontendTarget.fromRawPath matched the entityId: prefix case-sensitively
  and kept surrounding whitespace, so EntityId:light.kitchen opened as a path
  and a blank value became an empty path rather than the default dashboard.

Both now ignore case; fromRawPath also trims the value and maps a blank path
to the default dashboard.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@TimoPtr
TimoPtr requested a review from Copilot July 21, 2026 11:31
@TimoPtr
TimoPtr marked this pull request as ready for review July 21, 2026 11:31

@TimoPtr TimoPtr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for splitting this. I did update the documentation a little bit.

@TimoPtr
TimoPtr enabled auto-merge (squash) July 21, 2026 11:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves resilience when parsing hand-typed notification/deep-link targets by normalizing case (and, for frontend targets, surrounding whitespace), preventing misclassification of absolute URLs and entity-id targets.

Changes:

  • Make UrlUtil.isAbsoluteUrl match http/https schemes case-insensitively (fixing HTTPS://... being treated as relative).
  • Update FrontendTarget.fromRawPath to trim input, treat blank as default, and match entityId: prefix case-insensitively.
  • Add/extend unit tests to cover the new normalization behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
common/src/main/kotlin/io/homeassistant/companion/android/util/UrlUtil.kt Case-insensitive absolute-URL detection for http/https inputs.
common/src/test/kotlin/io/homeassistant/companion/android/util/UrlUtilTest.kt Adds parameterized coverage for mixed/upper-case schemes.
app/src/main/kotlin/io/homeassistant/companion/android/frontend/navigation/FrontendTarget.kt Normalizes raw frontend targets: trim + blank-to-default + case-insensitive entityId: handling.
app/src/test/kotlin/io/homeassistant/companion/android/frontend/navigation/FrontendTargetTest.kt Adds assertions for trimming/normalization of hand-typed frontend targets.

@TimoPtr
TimoPtr disabled auto-merge July 21, 2026 11:38
markfrancisonly and others added 2 commits July 21, 2026 08:01
Address review feedback: a value like `entityId:` with no id produced a
non-navigable EntityMoreInfo(""), it now maps to the default dashboard
like a blank path. isAbsoluteUrl reuses a single compiled regex and reads
the input with orEmpty() instead of relying on toString() for null.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@TimoPtr
TimoPtr enabled auto-merge (squash) July 21, 2026 12:20
@TimoPtr
TimoPtr disabled auto-merge July 21, 2026 12:50
@TimoPtr
TimoPtr merged commit f64c766 into home-assistant:main Jul 21, 2026
17 of 18 checks passed
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