Skip to content

Commit ce2b920

Browse files
authored
Merge pull request #671 from Rigelyon/fix-web-search
fix(web-search): Fix protocols other than http/https not recognized as URL
2 parents 12639c6 + 1932fa7 commit ce2b920

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

web-search/LauncherProvider.qml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,29 @@ Item {
3939
function isUrl(text) {
4040
if (!text || text.includes(" ")) return false;
4141

42-
if (/^https?:\/\//i.test(text)) return true;
42+
const protocolPattern = /^[a-z0-9]+:\/\/\S+/i;
43+
if (protocolPattern.test(text)) return true;
4344

44-
const localhostPattern = /^localhost(:[0-9]+)?(\/\S*)?$/i;
45+
const localhostPattern = /^localhost(\/\S*)?$/i;
4546
const ipPattern = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]+)?(\/\S*)?$/;
46-
const domainPattern = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]{2,})+(:[0-9]+)?(\/\S*)?$/;
47+
const domainPattern = /^([a-zA-Z0-9-]{1,63}\.)+[a-zA-Z]{2,}(:[0-9]+)?(\/\S*)?$/i;
48+
const hostPortPattern = /^[a-zA-Z0-9-]+:[0-9]+(\/\S*)?$/i;
4749

48-
return localhostPattern.test(text) || ipPattern.test(text) || domainPattern.test(text);
50+
return localhostPattern.test(text) || ipPattern.test(text) || domainPattern.test(text) || hostPortPattern.test(text);
4951
}
5052

5153
function normalizeUrl(text) {
5254
text = text.trim();
5355
if (!text) return "";
54-
if (/^[a-z0-9]+:\/\//i.test(text)) return text;
5556

56-
const isLocal = /^localhost(:[0-9]+)?(\/\S*)?$/i.test(text) ||
57-
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]+)?(\/\S*)?$/.test(text);
57+
const protocolPattern = /^[a-z0-9]+:\/\/\S+/i;
58+
if (protocolPattern.test(text)) return text;
59+
60+
const localhostPattern = /^localhost(\/\S*)?$/i;
61+
const ipPattern = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]+)?(\/\S*)?$/;
62+
const hostPortPattern = /^[a-zA-Z0-9-]+:[0-9]+(\/\S*)?$/i;
5863

59-
if (isLocal) {
64+
if (localhostPattern.test(text) || ipPattern.test(text) || hostPortPattern.test(text)) {
6065
return "http://" + text;
6166
}
6267

web-search/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ You can configure the plugin directly via Noctalia's Plugin Settings:
7373

7474
## Changelog
7575

76+
### 1.1.1
77+
- Fix protocols other than http/https not recognized as URL
78+
- Support for middle domain with only one character (e.g., www.a.com)
79+
- Support for hostname without dot with port (e.g., hostname:8080)
80+
- If you want to enter hostname without port and dot, you have to type the protocol manually
81+
7682
### 1.1.0
7783
- Added Direct URL Opening. Automatically detects URLs, IP addresses, and localhost and opens them directly in the browser
7884
- Added configurable toggle for the Direct URL feature

web-search/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "web-search",
33
"name": "Web Search",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"author": "Rigelyon",
66
"license": "MIT",
77
"description": "Search the Internet from the Launcher.",

0 commit comments

Comments
 (0)