question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix url validation in UrlInputPreference #1843 invalidates short URI's

See original GitHub issue

Actual 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:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
maniac103commented, May 11, 2020

I tested your suggestion val segments = httpClient.buildUrl(url).pathSegments and it works perfectly!

Great. Could you create a PR for that?

So I know this is an unusual request for a (one line) code change since the issue does not occur on a standard OpenHab2 Server. However, this one change would allow me to continue to leverage the Android client with my small platform OH ports.

If supporting that use case is as trivial as it’s the case here, IMHO it’s totally reasonable to support it.

0reactions
ewaldccommented, May 11, 2020

Done, thanks again for all the work on the Android client and your wonderful support!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Yup validation of website using url() very strict - Stack Overflow
I am trying to validate an input field as ...
Read more >
How To Validate Url In Go - Golang Cafe
In this blog post we talk about how to properly validate a URL in Go (Golang). URL stands for Unique Resource Locator, and...
Read more >
<input type="url"> - HTML: HyperText Markup Language | MDN
The input value is automatically validated to ensure that it's either empty or a properly-formatted URL before the form can be submitted.
Read more >
URL validation no working - Microsoft Q&A
URL validation no working. Hi,. Why below validation return valid for invalid URLs? if (!Uri.IsWellFormedUriString("microsoft", UriKind.
Read more >
Check if an URL is valid or not using Regular Expression
Given a URL as a character string str of size N.The task is to check if the given URL is valid or not....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found