From 9e14986e7fda35357f6d8b4012bf17bd178e0dfd Mon Sep 17 00:00:00 2001 From: divyansharma001 Date: Sat, 7 Mar 2026 22:23:40 +0530 Subject: [PATCH 1/2] 201_94: Fix slink bare URL redirect without HTTPS (#2324) --- TeXmacs/progs/link/link-navigate.scm | 21 +++++++++++++++++++++ devel/201_94.md | 16 ++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 devel/201_94.md diff --git a/TeXmacs/progs/link/link-navigate.scm b/TeXmacs/progs/link/link-navigate.scm index 84cb43c288..94027ee74a 100644 --- a/TeXmacs/progs/link/link-navigate.scm +++ b/TeXmacs/progs/link/link-navigate.scm @@ -546,10 +546,31 @@ (and (resolve-id id) (delayed (:idle 25) (apply go-to-id (cons id opt-from))))))) +(define (url-string-has-protocol? s) + "Check if a string already has a URL protocol prefix" + (or (string-starts? s "http://") + (string-starts? s "https://") + (string-starts? s "ftp://") + (string-starts? s "file://") + (string-starts? s "tmfs://") + (string-starts? s "blank://"))) + +(define (url-string-looks-like-web? s) + "Check if a string looks like a bare web URL without protocol" + (and (not (url-string-has-protocol? s)) + (not (string-starts? s "/")) + (not (string-starts? s ".")) + (not (string-starts? s "~")) + (not (string-starts? s "#")) + (string-index s #\.) + (not (url-exists? (system->url s))))) + (tm-define (go-to-url u . opt-from) (:synopsis "Jump to the url @u") (:argument opt-from "Optional path for the cursor history") (if (nnull? opt-from) (cursor-history-add (car opt-from))) + (when (and (string? u) (url-string-looks-like-web? u)) + (set! u (string-append "https://" u))) (if (string? u) (set! u (system->url u))) (with (action post) (url-handlers u) (action u) (post u)) diff --git a/devel/201_94.md b/devel/201_94.md new file mode 100644 index 0000000000..fb0531682d --- /dev/null +++ b/devel/201_94.md @@ -0,0 +1,16 @@ +# 201_94 Fix slink bare URL redirect without HTTPS + +## How to test +1. Type `slink`, press Enter, enter URL `liiistem.cn` +2. Ctrl+click the rendered link +3. Expected: browser opens `https://liiistem.cn` + +## 2026/03/07 Prepend https:// for bare domain URLs in slink +### What +When a user enters a bare domain like `liiistem.cn` in an slink (without `https://`), clicking the link now correctly opens it in the browser. + +### Why +Fixes #2324. Previously, bare domains were treated as local file paths because `go-to-url` routed them through `default-root-handler`. Since no local file exists, the link did nothing. + +### How +Added `url-string-looks-like-web?` check in `go-to-url` (link-navigate.scm) that detects bare domain strings (no protocol, contains a dot, not a local file path) and prepends `https://` before URL routing. From 9a4fe1911854b15177552d7162750d2114d0c84a Mon Sep 17 00:00:00 2001 From: divyansharma001 Date: Mon, 16 Mar 2026 00:14:39 +0530 Subject: [PATCH 2/2] Enhance bare domain detection in slink URLs to ensure correct resolution of local file links --- TeXmacs/progs/link/link-navigate.scm | 38 ++++++++++++---------------- devel/201_94.md | 12 +++++++++ 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/TeXmacs/progs/link/link-navigate.scm b/TeXmacs/progs/link/link-navigate.scm index 94027ee74a..6540f98f5d 100644 --- a/TeXmacs/progs/link/link-navigate.scm +++ b/TeXmacs/progs/link/link-navigate.scm @@ -497,12 +497,27 @@ ; TODO: jump to anchors in HTML (noop)) +(define (url-looks-like-bare-domain? u) + "Check if a default-rooted URL looks like a bare domain (e.g. liiistem.cn)" + (let* ((s (url->system u))) + (and (not (string-null? s)) + (not (string-starts? s "/")) + (not (string-starts? s ".")) + (not (string-starts? s "~")) + (not (string-index s #\space)) + (not (string-index s #\/)) + (string-index s #\.) + (not (url-exists? (url-expand u)))))) + (define (default-root-handler u) (cond ((and (url-rooted-protocol? u "default") (url-rooted-web? (current-buffer))) (default-root-handler (url-relative (current-buffer) u))) ((url-or? (url-expand u)) (default-root-disambiguator (url-expand u))) + ((url-looks-like-bare-domain? u) + (with web-url (system->url (string-append "https://" (url->system u))) + (http-root-handler web-url))) (else (with (base qry) (process-url u) (if (!= "" (url->system base)) @@ -546,33 +561,12 @@ (and (resolve-id id) (delayed (:idle 25) (apply go-to-id (cons id opt-from))))))) -(define (url-string-has-protocol? s) - "Check if a string already has a URL protocol prefix" - (or (string-starts? s "http://") - (string-starts? s "https://") - (string-starts? s "ftp://") - (string-starts? s "file://") - (string-starts? s "tmfs://") - (string-starts? s "blank://"))) - -(define (url-string-looks-like-web? s) - "Check if a string looks like a bare web URL without protocol" - (and (not (url-string-has-protocol? s)) - (not (string-starts? s "/")) - (not (string-starts? s ".")) - (not (string-starts? s "~")) - (not (string-starts? s "#")) - (string-index s #\.) - (not (url-exists? (system->url s))))) - (tm-define (go-to-url u . opt-from) (:synopsis "Jump to the url @u") (:argument opt-from "Optional path for the cursor history") (if (nnull? opt-from) (cursor-history-add (car opt-from))) - (when (and (string? u) (url-string-looks-like-web? u)) - (set! u (string-append "https://" u))) (if (string? u) (set! u (system->url u))) - (with (action post) (url-handlers u) + (with (action post) (url-handlers u) (action u) (post u)) (if (nnull? opt-from) (cursor-history-add (cursor-path)))) diff --git a/devel/201_94.md b/devel/201_94.md index 07e671a3ba..62bd3fbab4 100644 --- a/devel/201_94.md +++ b/devel/201_94.md @@ -5,6 +5,18 @@ 1. Type `slink`, press Enter, enter URL `liiistem.cn` 2. Ctrl+click the rendered link 3. Expected: browser opens `https://liiistem.cn` +4. Create a file `notes.pdf` next to the document, link to it via slink with `notes.pdf` +5. Ctrl+click — expected: opens the local file, NOT `https://notes.pdf` + +## 2026/03/15 Move bare domain detection into default-root-handler +### What +Bare domains like `liiistem.cn` in slinks now open in the browser, while file links like `notes.pdf` still resolve correctly as local files. + +### Why +The previous approach (prepending `https://` early in `go-to-url`) could misidentify file paths as web URLs because it checked file existence against the working directory, not relative to the current document. Moving the check into `default-root-handler` ensures file resolution (including relative paths) is attempted first. + +### How +Added `url-looks-like-bare-domain?` check in `default-root-handler` (link-navigate.scm). The check runs only after relative path resolution has been attempted, and only matches strings that have no slashes, contain a dot, and don't resolve to an existing file via `url-expand`. ## 2026/03/07 Prepend https:// for bare domain URLs in slink ### What