File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,15 @@ func findUrls(txt string) [][]int {
115115 return end
116116 }
117117
118+ // A dot at the end of a URL is most likely not part of the URL, but part of
119+ // the text. https://github.com/Debian/debiman/issues/140
120+ maybeStripDot := func (end int ) int {
121+ if txt [end - 1 ] == '.' {
122+ end --
123+ }
124+ return end
125+ }
126+
118127Outer:
119128 for i , r := range txt {
120129 // As per https://stackoverflow.com/a/1547940/712014:
@@ -150,6 +159,7 @@ Outer:
150159 }
151160 if inUrl {
152161 end := maybeStripParens (len (txt ))
162+ end = maybeStripDot (end )
153163 results = append (results , []int {lastWordBoundary + 1 , end })
154164 }
155165 return results
Original file line number Diff line number Diff line change @@ -450,3 +450,38 @@ func TestXrefHrefExclude(t *testing.T) {
450450 t .Fatalf ("Unexpected xref() HTML result: %v" , err )
451451 }
452452}
453+
454+ func TestXrefHrefExcludeDot (t * testing.T ) {
455+ input := & html.Node {
456+ Type : html .TextNode ,
457+ Data : "the upstream website goes into more detail at http://debian.org/." ,
458+ }
459+
460+ a1 := & html.Node {
461+ Type : html .ElementNode ,
462+ Data : "a" ,
463+ Attr : []html.Attribute {
464+ {Key : "href" , Val : "http://debian.org/" },
465+ },
466+ }
467+ a1 .AppendChild (& html.Node {
468+ Type : html .TextNode ,
469+ Data : "http://debian.org/" ,
470+ })
471+
472+ want := []* html.Node {
473+ & html.Node {
474+ Type : html .TextNode ,
475+ Data : "the upstream website goes into more detail at " ,
476+ },
477+ a1 ,
478+ & html.Node {
479+ Type : html .TextNode ,
480+ Data : "." ,
481+ },
482+ }
483+ got := xref (input .Data , func (ref string ) string { return ref })
484+ if err := cmpElems (input , got , want ); err != nil {
485+ t .Fatalf ("Unexpected xref() HTML result: %v" , err )
486+ }
487+ }
You can’t perform that action at this time.
0 commit comments