From 68fd4bc43da1be318aa43c2d1e24d97840b1ee7f Mon Sep 17 00:00:00 2001 From: piraces Date: Tue, 28 Feb 2023 23:28:56 +0100 Subject: [PATCH] feat: change strip html library to more stable one --- go.mod | 4 +++- go.sum | 8 ++++++-- pkg/feed/feed.go | 5 +++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index c7513b1..5f6c4c8 100644 --- a/go.mod +++ b/go.mod @@ -6,10 +6,10 @@ require ( github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/PuerkitoBio/goquery v1.8.1 github.com/fiatjaf/relayer v1.7.2 - github.com/grokify/html-strip-tags-go v0.0.1 github.com/hellofresh/health-go/v5 v5.1.0 github.com/kelseyhightower/envconfig v1.4.0 github.com/mattn/go-sqlite3 v1.14.16 + github.com/microcosm-cc/bluemonday v1.0.22 github.com/mmcdole/gofeed v1.2.0 github.com/nbd-wtf/go-nostr v0.13.2 github.com/rif/cache2go v1.0.0 @@ -20,12 +20,14 @@ require ( require ( github.com/SaveTheRbtz/generic-sync-map-go v0.0.0-20230201052002-6c5833b989be // indirect github.com/andybalholm/cascadia v1.3.1 // indirect + github.com/aymerick/douceur v0.2.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect github.com/google/go-cmp v0.5.9 // indirect + github.com/gorilla/css v1.0.0 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/json-iterator/go v1.1.12 // indirect diff --git a/go.sum b/go.sum index 9cee72a..d4fd10e 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/SaveTheRbtz/generic-sync-map-go v0.0.0-20230201052002-6c5833b989be h1 github.com/SaveTheRbtz/generic-sync-map-go v0.0.0-20230201052002-6c5833b989be/go.mod h1:ihkm1viTbO/LOsgdGoFPBSvzqvx7ibvkMzYp3CgtHik= github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c= github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= +github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= +github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 h1:KdUfX2zKommPRa+PD0sWZUyXe9w277ABlgELO7H04IM= @@ -23,12 +25,12 @@ github.com/fiatjaf/relayer v1.7.2/go.mod h1:cQGM8YSoU/7I79Mg9ULlLQWYm/U54/B/4k60 github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= +github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0= -github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78= github.com/hellofresh/health-go/v5 v5.1.0 h1:dxeIREsXQrO6D7+JEF++QPmqtRGhBclla5eLnCiKpSs= github.com/hellofresh/health-go/v5 v5.1.0/go.mod h1:ZUymhy/viIPx3xmGT9EkWny0CUZq9GLxqasC4Y2xdSc= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -41,6 +43,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/microcosm-cc/bluemonday v1.0.22 h1:p2tT7RNzRdCi0qmwxG+HbqD6ILkmwter1ZwVZn1oTxA= +github.com/microcosm-cc/bluemonday v1.0.22/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= github.com/mmcdole/gofeed v1.2.0 h1:kuq7tJnDf0pnsDzF820ukuySHxFimAcizpG15gYHIns= github.com/mmcdole/gofeed v1.2.0/go.mod h1:TEyTG4gw4Q5Co+Hgahx/Oi3E0JHLM8BXtWC+mkJtRsw= github.com/mmcdole/goxpp v0.0.0-20200921145534-2f3784f67354 h1:Z6i7ND25ixRtXFBylIUggqpvLMV1I15yprcqMVB7WZA= diff --git a/pkg/feed/feed.go b/pkg/feed/feed.go index 787c68f..b395949 100644 --- a/pkg/feed/feed.go +++ b/pkg/feed/feed.go @@ -9,7 +9,7 @@ import ( "errors" "fmt" "github.com/PuerkitoBio/goquery" - strip "github.com/grokify/html-strip-tags-go" + "github.com/microcosm-cc/bluemonday" "github.com/mmcdole/gofeed" "github.com/nbd-wtf/go-nostr" "github.com/piraces/rsslay/pkg/helpers" @@ -153,7 +153,8 @@ func ItemToTextNote(pubkey string, item *gofeed.Item, feed *gofeed.Feed, default content = "**" + item.Title + "**\n\n" } - description := strip.StripTags(item.Description) + p := bluemonday.StripTagsPolicy() + description := p.Sanitize(item.Description) if !strings.EqualFold(item.Title, description) { content += description