glanceapp / glance

A self-hosted dashboard that puts all your feeds in one place
GNU Affero General Public License v3.0
8.56k stars 297 forks source link

Search bar acts like address bar feature implemented #256

Open develoopeer opened 1 week ago

develoopeer commented 1 week ago

Feature from #229 issue implemented with the following behavior:

If string passed from input is a valid URL, tab with this string will be opened, not the search engine with URL as a search request.

URL from search input field will be considered valid, if they are corresponding to RFC 3886, Generic Syntax of URI`s. That does mean that string:

svilenmarkov commented 1 week ago

Hey, thanks for contributing!

I'm not sure there's any benefit to strictly following the URI RFC, as in my browser's address bar I can simply type google.com which would be treated as a valid address. Plus, I don't think anyone would actually want to fully type https:// every time.

Something like the following regex should probably suffice in returning true for isValidUrl as a backup when the URL instantiation fails:

^(?:[a-z0-9-]+\.)+[a-z]+$
develoopeer commented 1 week ago

The benefit of following the URI RFC is the fact, that you can pass URI to javascript window.open function directly. If string like google.com will be passed to it, address of current page will be prepend to URL, and you will get localhost/google.com. You need to prepend a scheme to string by yourself.

But i feel like you noticed correctly. No one would type https:// manually, or even if you have URL string in OS buffer, you will pass it to your browser, not to the search widget.