Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe committed Nov 25, 2023
1 parent 15fe6c9 commit 3820491
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions link_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var atomToAttributes = map[atom.Atom][]string{
atom.Meta: {"content"},
}

var imageDescriptorPattern = regexp.MustCompile(" [^ ]*$")
var imageDescriptorPattern = regexp.MustCompile(`(\S)\s+\S+\s*$`)

type linkFinder struct {
linkFilterer linkFilterer
Expand Down Expand Up @@ -75,7 +75,7 @@ func (f linkFinder) parseLinks(n *html.Node, a string) []string {
switch a {
case "srcset":
for _, s := range strings.Split(s, ",") {
ss = append(ss, imageDescriptorPattern.ReplaceAllString(f.trimSpace(s), ""))
ss = append(ss, f.trimSpace(imageDescriptorPattern.ReplaceAllString(s, "$1")))
}
case "content":
switch scrape.Attr(n, "property") {
Expand Down
11 changes: 3 additions & 8 deletions link_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,18 @@ func TestLinkFinderFindMetaTags(t *testing.T) {
assert.Nil(t, err)
}

func TestLinkFinderFindLinkWithSpaces(t *testing.T) {
func TestLinkFinderFindDataSchemeLinkWithSpaces(t *testing.T) {
b, err := url.Parse("http://foo.com")
assert.Nil(t, err)

n, err := html.Parse(strings.NewReader(
htmlWithBody(`
<a href="http:
//foo.com
/
foo.html" />
`)),
htmlWithBody(`<a href="data:text/plain, Hello,%20world! " />`)),
)
assert.Nil(t, err)

ls := newTestLinkFinder().Find(n, b)

err, ok := ls["http://foo.com/foo.html"]
err, ok := ls["data:text/plain, Hello,%20world!"]
assert.True(t, ok)
assert.Nil(t, err)
}
Expand Down

0 comments on commit 3820491

Please sign in to comment.