Bläddra i källkod

more systematic bad-character check in permissive mode

tags/v2.0.0-rc1
Shivaram Lingamneni 4 år sedan
förälder
incheckning
781bb6b051
2 ändrade filer med 10 tillägg och 4 borttagningar
  1. 9
    4
      irc/strings.go
  2. 1
    0
      irc/strings_test.go

+ 9
- 4
irc/strings.go Visa fil

@@ -7,6 +7,7 @@ package irc
7 7
 
8 8
 import (
9 9
 	"fmt"
10
+	"regexp"
10 11
 	"strings"
11 12
 	"unicode"
12 13
 
@@ -21,6 +22,12 @@ const (
21 22
 	precisUTF8MappingToken = "rfc8265"
22 23
 )
23 24
 
25
+var (
26
+	// reviving the old ergonomadic nickname regex:
27
+	// in permissive mode, allow arbitrary letters, numbers, punctuation, and symbols
28
+	permissiveCharsRegex = regexp.MustCompile(`^[\pL\pN\pP\pS]*$`)
29
+)
30
+
24 31
 type Casemapping uint
25 32
 
26 33
 const (
@@ -271,10 +278,8 @@ func IsPureASCII(str string) bool {
271 278
 }
272 279
 
273 280
 func foldPermissive(str string) (result string, err error) {
274
-	for _, r := range str {
275
-		if unicode.IsSpace(r) || r == 0 {
276
-			return "", errInvalidCharacter
277
-		}
281
+	if !permissiveCharsRegex.MatchString(str) {
282
+		return "", errInvalidCharacter
278 283
 	}
279 284
 	// YOLO
280 285
 	str = norm.NFD.String(str)

+ 1
- 0
irc/strings_test.go Visa fil

@@ -237,6 +237,7 @@ func TestFoldPermissive(t *testing.T) {
237 237
 	tester("shivaram", "DAN-", false)
238 238
 	tester("dolph🐬n", "DOLPH🐬n", true)
239 239
 	tester("dolph🐬n", "dolph💻n", false)
240
+	tester("9FRONT", "9front", true)
240 241
 }
241 242
 
242 243
 func TestFoldPermissiveInvalid(t *testing.T) {

Laddar…
Avbryt
Spara