Browse Source

disallow some bad characters in foldPermissive

tags/v2.0.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
2d4dbeba1c
2 changed files with 17 additions and 0 deletions
  1. 5
    0
      irc/strings.go
  2. 12
    0
      irc/strings_test.go

+ 5
- 0
irc/strings.go View File

@@ -271,6 +271,11 @@ func IsPureASCII(str string) bool {
271 271
 }
272 272
 
273 273
 func foldPermissive(str string) (result string, err error) {
274
+	for _, r := range str {
275
+		if unicode.IsSpace(r) || r == 0 {
276
+			return "", errInvalidCharacter
277
+		}
278
+	}
274 279
 	// YOLO
275 280
 	str = norm.NFD.String(str)
276 281
 	str = cases.Fold().String(str)

+ 12
- 0
irc/strings_test.go View File

@@ -63,6 +63,7 @@ func TestCasefoldChannel(t *testing.T) {
63 63
 		"", "#*starpower", "# NASA", "#interro?", "OOF#", "foo",
64 64
 		// bidi violation mixing latin and hebrew characters:
65 65
 		"#shalomעליכם",
66
+		"#tab\tcharacter", "#\t", "#carriage\rreturn",
66 67
 	} {
67 68
 		testCases = append(testCases, channelTest{channel: errCase, err: true})
68 69
 	}
@@ -237,3 +238,14 @@ func TestFoldPermissive(t *testing.T) {
237 238
 	tester("dolph🐬n", "DOLPH🐬n", true)
238 239
 	tester("dolph🐬n", "dolph💻n", false)
239 240
 }
241
+
242
+func TestFoldPermissiveInvalid(t *testing.T) {
243
+	_, err := foldPermissive("a\tb")
244
+	if err == nil {
245
+		t.Errorf("whitespace should be invalid in identifiers")
246
+	}
247
+	_, err = foldPermissive("a\x00b")
248
+	if err == nil {
249
+		t.Errorf("the null byte should be invalid in identifiers")
250
+	}
251
+}

Loading…
Cancel
Save