diff --git a/TeXmacs/progs/link/link-navigate.scm b/TeXmacs/progs/link/link-navigate.scm index 84cb43c288..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)) @@ -551,7 +566,7 @@ (:argument opt-from "Optional path for the cursor history") (if (nnull? opt-from) (cursor-history-add (car opt-from))) (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 e3fea0cff7..62bd3fbab4 100644 --- a/devel/201_94.md +++ b/devel/201_94.md @@ -1,8 +1,30 @@ -# [201_94] -## 如何测试 +# 201_94 Fix slink bare URL redirect without HTTPS -1. 打开`TeXmacs/tests/tmu/201_94.tmu`. -2. 选中注记点击编辑宏,观察程序是否会crash +## 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` +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 +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. -## 2026/03/10 修复宏编辑器crash的问题