mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
fix #306
Fix spurious bidi rule violations in casefolding channel names by stripping the # before starting the casefolding.
This commit is contained in:
parent
70364f5f67
commit
40e63dbbe8
@ -39,18 +39,25 @@ func Casefold(str string) (string, error) {
|
|||||||
|
|
||||||
// CasefoldChannel returns a casefolded version of a channel name.
|
// CasefoldChannel returns a casefolded version of a channel name.
|
||||||
func CasefoldChannel(name string) (string, error) {
|
func CasefoldChannel(name string) (string, error) {
|
||||||
lowered, err := Casefold(name)
|
if len(name) == 0 {
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
} else if len(lowered) == 0 {
|
|
||||||
return "", errStringIsEmpty
|
return "", errStringIsEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
if lowered[0] != '#' {
|
// don't casefold the preceding #'s
|
||||||
|
var start int
|
||||||
|
for start = 0; start < len(name) && name[start] == '#'; start += 1 {
|
||||||
|
}
|
||||||
|
|
||||||
|
if start == 0 {
|
||||||
|
// no preceding #'s
|
||||||
return "", errInvalidCharacter
|
return "", errInvalidCharacter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lowered, err := Casefold(name[start:])
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
// space can't be used
|
// space can't be used
|
||||||
// , is used as a separator
|
// , is used as a separator
|
||||||
// * is used in mask matching
|
// * is used in mask matching
|
||||||
@ -59,7 +66,7 @@ func CasefoldChannel(name string) (string, error) {
|
|||||||
return "", errInvalidCharacter
|
return "", errInvalidCharacter
|
||||||
}
|
}
|
||||||
|
|
||||||
return lowered, err
|
return name[:start] + lowered, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CasefoldName returns a casefolded version of a nick/user name.
|
// CasefoldName returns a casefolded version of a nick/user name.
|
||||||
|
@ -40,10 +40,21 @@ func TestCasefoldChannel(t *testing.T) {
|
|||||||
channel: "#",
|
channel: "#",
|
||||||
folded: "#",
|
folded: "#",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
channel: "#中文频道",
|
||||||
|
folded: "#中文频道",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Hebrew; it's up to the client to display this right-to-left, including the #
|
||||||
|
channel: "#שלום",
|
||||||
|
folded: "#שלום",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, errCase := range []string{
|
for _, errCase := range []string{
|
||||||
"", "#*starpower", "# NASA", "#interro?", "OOF#", "foo",
|
"", "#*starpower", "# NASA", "#interro?", "OOF#", "foo",
|
||||||
|
// bidi violation mixing latin and hebrew characters:
|
||||||
|
"#shalomעליכם",
|
||||||
} {
|
} {
|
||||||
testCases = append(testCases, channelTest{channel: errCase, err: true})
|
testCases = append(testCases, channelTest{channel: errCase, err: true})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user