Skip to content

Commit 37c4c2f

Browse files
authored
Merge pull request #75 from upfluence/thomasgallice/lib-173-influencers-email-wrongly-identified-through-igs-bio-peachy
stringutil/decoder: Until remove not ascii use space to separe work
2 parents 851efda + 440474e commit 37c4c2f

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

stringutil/decoder.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package stringutil
22

33
import (
4+
"regexp"
45
"strings"
56
"unicode"
67
"unicode/utf8"
@@ -75,6 +76,8 @@ func IsASCII(s string) bool {
7576
return true
7677
}
7778

79+
var spaceRegex = regexp.MustCompile(`\s+`)
80+
7881
func DecodeToASCII(s string, opts ...ASCIIDecodeOption) string {
7982
if IsASCII(s) {
8083
return s
@@ -90,7 +93,13 @@ func DecodeToASCII(s string, opts ...ASCIIDecodeOption) string {
9093
t = transform.Chain(
9194
os.decomposer,
9295
runes.Remove(runes.In(unicode.Mn)),
93-
runes.Remove(setFunc(isAboveASCII)),
96+
runes.Map(func(r rune) rune {
97+
if isAboveASCII(r) {
98+
return rune(' ')
99+
}
100+
101+
return r
102+
}),
94103
os.composer,
95104
)
96105

@@ -102,5 +111,5 @@ func DecodeToASCII(s string, opts ...ASCIIDecodeOption) string {
102111
return ""
103112
}
104113

105-
return result
114+
return strings.Trim(spaceRegex.ReplaceAllString(result, " "), " ")
106115
}

stringutil/decoder_test.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,20 @@ func TestDecodeToASCII(t *testing.T) {
4141
},
4242
{
4343
in: "Collaboration: 𝕸𝖎𝖆𝖒𝖎 🌞 x KiwiKurve",
44-
out: "Collaboration: x KiwiKurve",
44+
out: "Collaboration: x KiwiKurve",
4545
},
4646
{
4747
in: "Collaboration: 𝕸𝖎𝖆𝖒𝖎 🌞 x KiwiKurve",
48-
out: "Collaboration: Miami x KiwiKurve",
48+
out: "Collaboration: Miami x KiwiKurve",
49+
opts: nfkd,
50+
},
51+
{
52+
in: "back soon ✌🏽📍ashleyrchand@gmail.com",
53+
out: "back soon ashleyrchand@gmail.com",
54+
},
55+
{
56+
in: "Golden Girl 🌴\n🌿Discounts/links⬇️\nPR/Collab📧spfpleaseka𝐓ie@gmail.com",
57+
out: "Golden Girl Discounts/links PR/Collab spfpleasekaTie@gmail.com",
4958
opts: nfkd,
5059
},
5160
{

0 commit comments

Comments
 (0)