Skip to content

Commit

Permalink
🐛 Lost URL content after : when pasting as a link siyuan-note/siyua…
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed May 11, 2024
1 parent 6b3ecaf commit ee3fcf0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion javascript/lute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/lute.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion parse/auto_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (t *Tree) parseGFMAutoLink0(node *ast.Node) {
}

// 判断端口后部分是否为数字
if tmp := bytes.ReplaceAll(url, []byte("://"), nil); bytes.Contains(tmp, []byte(":")) {
if tmp := bytes.ReplaceAll(url, []byte("://"), nil); bytes.Contains(tmp, []byte(":")) && !bytes.Contains(tmp, []byte("/")) {
tmp = tmp[bytes.Index(tmp, []byte(":"))+1:]
if !bytes.Contains(tmp, []byte("/")) && !lex.IsDigit(token) && lex.ItemSlash != token {
break
Expand Down
1 change: 1 addition & 0 deletions test/autolink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

var autoLinkTests = []parseTest{

{"30", "https://foo.com/bar:baz", "<p><a href=\"https://foo.com/bar:baz\">https://foo.com/bar:baz</a></p>\n"},
{"29", "www.test.com:8080/bar/baz", "<p><a href=\"http://www.test.com:8080/bar/baz\">www.test.com:8080/bar/baz</a></p>\n"},
{"28", "www.test.com:8080(测试地址)", "<p><a href=\"http://www.test.com:8080\">www.test.com:8080</a>(测试地址)</p>\n"},
{"27", "http://127.0.0.1:8080(测试地址)", "<p><a href=\"http://127.0.0.1:8080\">http://127.0.0.1:8080</a>(测试地址)</p>\n"},
Expand Down
7 changes: 6 additions & 1 deletion test/link_dest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import (
func TestGetLinkDest(t *testing.T) {
luteEngine := lute.New()

dest := luteEngine.GetLinkDest("[foo](bar.com)")
dest := luteEngine.GetLinkDest("https://foo.com/bar:baz")
if "https://foo.com/bar:baz" != dest {
t.Fatalf("get link dest failed")
}

dest = luteEngine.GetLinkDest("[foo](bar.com)")
if "bar.com" != dest {
t.Fatalf("get link dest failed")
}
Expand Down

0 comments on commit ee3fcf0

Please sign in to comment.