Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion TeXmacs/progs/link/link-navigate.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))))

Expand Down
32 changes: 27 additions & 5 deletions devel/201_94.md
Original file line number Diff line number Diff line change
@@ -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的问题