fix: strip HTML tags when displaying account info
This commit is contained in:
parent
0471ac817f
commit
70fc1acc68
2 changed files with 24 additions and 4 deletions
|
@ -4,9 +4,11 @@ import (
|
|||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
var instanceDetailsFormat = `INSTANCE:
|
||||
|
@ -134,7 +136,7 @@ func (c *showCommand) showAccount(gts *client.Client) error {
|
|||
metadata := ""
|
||||
|
||||
for _, field := range account.Fields {
|
||||
metadata += fmt.Sprintf("\n %s: %s", field.Name, field.Value)
|
||||
metadata += fmt.Sprintf("\n %s: %s", field.Name, stripHTMLTags(field.Value))
|
||||
}
|
||||
|
||||
fmt.Printf(
|
||||
|
@ -146,10 +148,26 @@ func (c *showCommand) showAccount(gts *client.Client) error {
|
|||
account.FollowersCount,
|
||||
account.FollowingCount,
|
||||
account.StatusCount,
|
||||
account.Note,
|
||||
stripHTMLTags(account.Note),
|
||||
metadata,
|
||||
account.URL,
|
||||
)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func stripHTMLTags(text string) string {
|
||||
token := html.NewTokenizer(strings.NewReader(text))
|
||||
|
||||
var builder strings.Builder
|
||||
|
||||
for {
|
||||
tt := token.Next()
|
||||
switch tt {
|
||||
case html.ErrorToken:
|
||||
return builder.String()
|
||||
case html.TextToken:
|
||||
builder.WriteString(token.Token().Data + " ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
6
go.mod
6
go.mod
|
@ -2,11 +2,13 @@ module codeflow.dananglin.me.uk/apollo/enbas
|
|||
|
||||
go 1.22.0
|
||||
|
||||
require golang.org/x/oauth2 v0.17.0
|
||||
require (
|
||||
golang.org/x/net v0.21.0
|
||||
golang.org/x/oauth2 v0.17.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
golang.org/x/net v0.21.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue