Editor:
- Toggles (Tiptap Details). Open state is per reader, not saved.
- Embeds for YouTube, Vimeo, Loom, Figma, CodePen, Spotify, Google Docs
and Maps, in sandboxed frames. Other addresses become link cards.
- Link cards with title, description and picture read by docwell-server
(GET /link-preview). The fetcher refuses private, loopback, link-local
and CGNAT addresses after DNS resolution, redirects included.
- Block links: a margin button gives a block a short id and copies
/p/<id>#b-<block>. Opening one jumps to the block and flashes it.
- Markdown, HTML and PDF exports handle the new blocks; HTML import reads
<details> as a toggle.
Pages and spaces:
- History gets a Changes view: block and word diff against the previous
version or the page as it is now.
- Archive: archived pages leave the tree and become read-only but stay
readable; a space's Archive lists them with Unarchive. New migration
(pages.archived_at) and page.archived / page.unarchived webhook events.
- Full space export (GET /spaces/{id}/export): a zip of Markdown or HTML
files with subpages in folders, an index, and attachments under _files/.
Links between exported pages and to attachments become relative paths.
Desktop 1.0:
- Several servers, each with its own sign-in; old settings files carry over.
- Session tokens in the system keychain (go-keyring), moved out of
localStorage on first start.
- Native menu bar (File, Edit, View, Window, Help) with a Server submenu.
- docwell:// links may point at a block.
- Release workflow builds Windows NSIS, macOS DMG and Linux deb, rpm and
AppImage installers and attaches them to the release;
build/set-version.mjs stamps the version into their metadata.
Not yet run: the release workflow, the desktop menus by eye, and macOS or
Linux builds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
2.5 KiB
Go
83 lines
2.5 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package unfurl
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
base, _ := url.Parse("https://example.com/blog/post")
|
|
page := `<!doctype html><html><head>
|
|
<title> Fallback title </title>
|
|
<meta property="og:title" content="Docwell & friends">
|
|
<meta name="description" content="Plain description">
|
|
<meta property="og:site_name" content="Example Blog">
|
|
<meta property="og:image" content="/img/cover.png">
|
|
</head><body><meta property="og:title" content="ignored"></body></html>`
|
|
p := Parse(base, strings.NewReader(page))
|
|
if p.Title != "Docwell & friends" || p.Description != "Plain description" || p.Site != "Example Blog" {
|
|
t.Fatalf("got %+v", p)
|
|
}
|
|
if p.Image != "https://example.com/img/cover.png" {
|
|
t.Fatalf("image = %q", p.Image)
|
|
}
|
|
|
|
p = Parse(base, strings.NewReader(`<title>Only a title</title><meta property="og:image" content="javascript:alert(1)">`))
|
|
if p.Title != "Only a title" || p.Image != "" {
|
|
t.Fatalf("got %+v", p)
|
|
}
|
|
}
|
|
|
|
func TestPublic(t *testing.T) {
|
|
for _, s := range []string{"127.0.0.1", "10.1.2.3", "192.168.1.1", "172.16.0.1", "169.254.169.254", "100.64.0.1", "::1", "fd00::1", "0.0.0.0"} {
|
|
if Public(net.ParseIP(s)) {
|
|
t.Errorf("%s counted as public", s)
|
|
}
|
|
}
|
|
for _, s := range []string{"1.1.1.1", "93.184.216.34", "2606:4700::1111"} {
|
|
if !Public(net.ParseIP(s)) {
|
|
t.Errorf("%s counted as private", s)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPreviewRefusesLocalAddresses(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
_, _ = w.Write([]byte(`<title>secret</title>`))
|
|
}))
|
|
defer srv.Close()
|
|
p, err := New().Preview(context.Background(), srv.URL)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// The fetch is refused, so the card has only the address.
|
|
if p.Title != "" || p.URL != srv.URL {
|
|
t.Fatalf("got %+v", p)
|
|
}
|
|
}
|
|
|
|
func TestPreviewFetches(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
_, _ = w.Write([]byte(`<head><meta property="og:title" content="Hello"></head>`))
|
|
}))
|
|
defer srv.Close()
|
|
p, err := NewWithClient(srv.Client()).Preview(context.Background(), srv.URL+"/#part")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if p.Title != "Hello" || p.URL != srv.URL+"/" || p.Site != "127.0.0.1" {
|
|
t.Fatalf("got %+v", p)
|
|
}
|
|
if _, err := New().Preview(context.Background(), "file:///etc/passwd"); err == nil {
|
|
t.Fatal("file: address accepted")
|
|
}
|
|
}
|