diff options
author | 2023-09-29 10:39:56 +0200 | |
---|---|---|
committer | 2023-09-29 10:39:56 +0200 | |
commit | 536d9e482d4ebc012855372b9fcfa4f022d1618a (patch) | |
tree | 36079fb403b9a9bb7d3a64ace582c6870bcce77b /internal/text/normalize.go | |
parent | [bugfix] Move follow.show_reblogs check further up to avoid showing unwanted ... (diff) | |
download | gotosocial-536d9e482d4ebc012855372b9fcfa4f022d1618a.tar.xz |
[chore/bugfix] Deinterface text.Formatter, allow underscores in hashtags (#2233)
Diffstat (limited to 'internal/text/normalize.go')
-rw-r--r-- | internal/text/normalize.go | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/internal/text/normalize.go b/internal/text/normalize.go index 14caf6311..d2e633d1e 100644 --- a/internal/text/normalize.go +++ b/internal/text/normalize.go @@ -20,7 +20,6 @@ package text import ( "strings" - "github.com/superseriousbusiness/gotosocial/internal/util" "golang.org/x/text/unicode/norm" ) @@ -36,8 +35,10 @@ const ( // // Finally, it will do a check on the normalized string to // ensure that it's below maximumHashtagLength chars, and -// contains only unicode letters and numbers. If this passes, -// returned bool will be true. +// contains only letters, numbers, and underscores (and not +// *JUST* underscores). +// +// If all this passes, returned bool will be true. func NormalizeHashtag(text string) (string, bool) { // This normalization is specifically to avoid cases // where visually-identical hashtags are stored with @@ -47,14 +48,31 @@ func NormalizeHashtag(text string) (string, bool) { // with parent characters to form regular letter symbols. normalized := norm.NFC.String(strings.TrimPrefix(text, "#")) - // Validate normalized. - ok := true + // Validate normalized result. + var ( + notJustUnderscores = false + onlyPermittedChars = true + lengthOK = true + ) + for i, r := range normalized { - if i >= maximumHashtagLength || !util.IsPermittedInHashtag(r) { - ok = false + if r != '_' { + // This isn't an underscore, + // so the whole hashtag isn't + // just underscores. + notJustUnderscores = true + } + + if i >= maximumHashtagLength { + lengthOK = false + break + } + + if !isPermittedInHashtag(r) { + onlyPermittedChars = false break } } - return normalized, ok + return normalized, (lengthOK && onlyPermittedChars && notJustUnderscores) } |