From b9474de2bef8469a61b22ba17f18c28ab4c58fd8 Mon Sep 17 00:00:00 2001 From: Gary Burd Date: Thu, 2 Feb 2012 17:02:05 -0800 Subject: [PATCH] go/doc: Fix URL linking in ToHTML. Fixes issue: 2832 R=rsc, gri CC=golang-dev https://golang.org/cl/5616060 --- src/pkg/go/doc/comment.go | 8 ++++---- src/pkg/go/doc/comment_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/pkg/go/doc/comment.go b/src/pkg/go/doc/comment.go index e50cdd86e6..6f0edd4bad 100644 --- a/src/pkg/go/doc/comment.go +++ b/src/pkg/go/doc/comment.go @@ -56,7 +56,7 @@ const ( filePart + `([:.,]` + filePart + `)*` ) -var matchRx = regexp.MustCompile(`(` + identRx + `)|(` + urlRx + `)`) +var matchRx = regexp.MustCompile(`(` + urlRx + `)|(` + identRx + `)`) var ( html_a = []byte(`http://www.google.com/`}, + {"https://www.google.com/", `https://www.google.com/`}, + {"http://www.google.com/path.", `http://www.google.com/path.`}, + {"(http://www.google.com/)", `(http://www.google.com/)`}, + {"Foo bar http://example.com/ quux!", `Foo bar http://example.com/ quux!`}, + {"Hello http://example.com/%2f/ /world.", `Hello http://example.com/%2f/ /world.`}, + {"Lorem http: ipsum //host/path", "Lorem http: ipsum //host/path"}, + {"javascript://is/not/linked", "javascript://is/not/linked"}, +} + +func TestEmphasize(t *testing.T) { + for i, tt := range emphasizeTests { + var buf bytes.Buffer + emphasize(&buf, tt.in, nil, true) + out := buf.String() + if out != tt.out { + t.Errorf("#%d: mismatch\nhave: %v\nwant: %v", i, out, tt.out) + } + } +} -- 2.50.0