Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@TimoPtr
Copy link
Member

@TimoPtr TimoPtr commented Nov 12, 2025

Summary

While looking at Sentry crashes I found out that there was a case not handled by the handle function in UrlUtil, where a string like http://h:8123None can be parsed as a URI but then .toURL would crash with NumberFormatException.

To fix this I've asked Claude to first generate a set of tests, to be able to reproduce the issue (it was not trivial to found a case that triggers the issue from the crash only).
Then once identified I took the liberty to change the implementation with more details.

image This only crashes when something is wrong in the URL. But it might happens since it's retrieved from a notification so a user could make a mistake.

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.

Comment on lines 71 to 72
// assertEquals("https://example.com:8123/https:/example.com/path", result.toString())
assertEquals("https://example.com:8123/path", result.toString())
Copy link
Member Author

Choose a reason for hiding this comment

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

@jpelgrom could you check this test in particular? The comments are from Claude and I didn't want to apply his suggestion until we discuss it. Which are to test the isAbsolute onto the normalizedInput instead of the input.

Copy link
Member

Choose a reason for hiding this comment

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

Nice find, I suppose.

It is supposed to be a custom URI scheme specifically to be used for creating a URL relative to your Home Assistant server, which is needed because your base URL may change (internal/external). Always treating it as relative therefore makes the most sense to me.

The current check does that, indirectly (homeassistant protocol != http(s), so not absolute). After thinking about it, I'd probably keep it as it is right now because:

  • changing it to check the normalized input does mean that weird input like here can end up being treated like a absolute url, which is explicitly not intended
  • we have a custom scheme so can simply say it's not supported (and HA doesn't have paths like this)
  • checking it as absolute may also makes it easier to have a redirect attack (external app opens LinkActivity with homeassistant://navigate/a; currently you end up on your server, and we have checks to get out of the WebViewActivity if the host is different, but why risk it?)

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the test to remove the comments and make the title more explicit.

@TimoPtr TimoPtr requested a review from jpelgrom November 12, 2025 13:39
@github-actions
Copy link
Contributor

github-actions bot commented Nov 12, 2025

Test Results

 92 files    1 errors  91 suites   10m 38s ⏱️
746 tests 746 ✅ 0 💤 0 ❌
761 runs  761 ✅ 0 💤 0 ❌

For more details on these parsing errors, see this check.

Results for commit 381c316.

♻️ This comment has been updated with latest results.

@TimoPtr
Copy link
Member Author

TimoPtr commented Nov 12, 2025

Test reporting are failing because the XML contains all the logs when the tests are running and it's too big for the tool we use to proceed.

#5846

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