Fix url validation in UrlInputPreference #1843 invalidates short URI's
See original GitHub issueActual behaviour
Until recently, OpenHab servers/services returning short URI’s worked OK. After changes implemented by #1843 like changing url.toUri() to url.toHttpUrlOrNull() short URI’s are no longer accepted in all conditions.
Most of the time these code changes cause not problems, e.g. when the URI is based on the localHost or remoteHost (e.g. when testing if the OpenHab server can be reached) but in some case it does cause problems e.g. mobile/src/main/java/org/openhab/habdroid/ui/activity/PageConnectionHolderFragment.kt :
- val segments = url.toUri().pathSegments
+ val segments = url.toHttpUrlOrNull()?.pathSegments ?: emptyList()
In this case the URI comes out of JSON code returned by the server and when the URI is a short URI, it causes the value segments to become emptyList() and consequently the SSE EventHelper is no longer called.
Expected behaviour
According to RFC 2396, an URI generic syntax consists of a hierarchical sequence of five components:
URI = scheme:[//authority]path[?query][#fragment]
where the (optional) authority component divides into three subcomponents:
authority = [userinfo@]host[:port]
Hence, I believe a short URI like /rest/sitemaps/demo/demo should be considered valid.
Previously the code was just prepending the localHost or remoteHost string to URI to form a valid URI. Maybe that is the best solution for cases where the URI comes out of server returned JSON code: if toHttpUrlOrNull() returns null, redo the test with the current host (local or remote) prefixed to the URI. In that case the URI will be valid.
Steps to reproduce
Any OpenHab2 service (2.4 or 2.5 tested) returning short URI’s.
Can you reproduce the issue in demo mode?
have not tried, seems irrelevant
Environment data
Client
- Android version: irrelevant
- Device model: irrelevant
- App version: any version after #1843 changes
- Build flavor :
- Device language:
Logs
App log
Click to expand
Please add the app log if the issue is not a pure UI issue or it cannot be reproduced in demo mode.
Open the app, go to `Settings` => `View log` and insert the log here.
openHAB Server log
logcat shows certain functions being skipped e.g. SSE Helper
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)

Top Related StackOverflow Question
Great. Could you create a PR for that?
If supporting that use case is as trivial as it’s the case here, IMHO it’s totally reasonable to support it.
Done, thanks again for all the work on the Android client and your wonderful support!