Allow tabs in messages
This commit is contained in:
parent
607d445c93
commit
6abb09b0c9
|
@ -415,7 +415,7 @@ void writeallx_u16(int fd, uint16_t value) {
|
|||
writeallx(fd, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
bool check_utf8(const unsigned char *data, size_t data_length, bool newline_allowed);
|
||||
bool check_utf8(const unsigned char *data, size_t data_length, bool newline_tab_allowed);
|
||||
|
||||
void read_status(void) {
|
||||
unsigned char status;
|
||||
|
@ -503,7 +503,7 @@ bool check_padding(const unsigned char *data, size_t index, size_t data_length)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool check_utf8(const unsigned char *data, size_t data_length, bool newline_allowed) {
|
||||
bool check_utf8(const unsigned char *data, size_t data_length, bool newline_tab_allowed) {
|
||||
size_t remaining = 0;
|
||||
size_t length = 0;
|
||||
uint32_t codepoint = 0;
|
||||
|
@ -595,7 +595,7 @@ bool check_utf8(const unsigned char *data, size_t data_length, bool newline_allo
|
|||
// Reject control characters
|
||||
if (codepoint <= 0x1f) {
|
||||
// C0 control character
|
||||
if (!newline_allowed || codepoint != 0x0a) {
|
||||
if (!newline_tab_allowed || (codepoint != 0x0a && codepoint != 0x09)) {
|
||||
return false;
|
||||
}
|
||||
} else if (0x80 <= codepoint && codepoint <= 0x9f) {
|
||||
|
|
|
@ -130,7 +130,7 @@ def timestamp():
|
|||
class NonCharacterError(Exception): pass
|
||||
class ControlCharacterError(Exception): pass
|
||||
|
||||
def validate_encoding(text, newline_allowed):
|
||||
def validate_encoding(text, newline_tab_allowed):
|
||||
# We assume text is valid unicode, so we skip stuff like surrogate pairs
|
||||
|
||||
for char in text:
|
||||
|
@ -146,7 +146,7 @@ def validate_encoding(text, newline_allowed):
|
|||
# Reject control characters
|
||||
if codepoint <= 0x1f:
|
||||
# C0 control characters
|
||||
if not newline_allowed or codepoint != 0x0a:
|
||||
if not newline_tab_allowed or codepoint not in [0x0a, 0x09]:
|
||||
raise ControlCharacterError(char)
|
||||
elif 0x80 <= codepoint <= 0x9f:
|
||||
# C1 control characters
|
||||
|
@ -158,7 +158,7 @@ def validate_encoding(text, newline_allowed):
|
|||
class NickLengthError(Exception): pass
|
||||
|
||||
def validate_nick(nick):
|
||||
validate_encoding(nick, newline_allowed = False)
|
||||
validate_encoding(nick, newline_tab_allowed = False)
|
||||
# Nick length is stored as one byte
|
||||
if len(nick.encode('utf-8')) > 255:
|
||||
raise NickLengthError
|
||||
|
@ -166,7 +166,7 @@ def validate_nick(nick):
|
|||
class MessageLengthError(Exception): pass
|
||||
|
||||
def validate_message(message):
|
||||
validate_encoding(message, newline_allowed = True)
|
||||
validate_encoding(message, newline_tab_allowed = True)
|
||||
# Maximum frame payload is 1500 bytes
|
||||
# -2 for EtherMess packet header
|
||||
# -2 for msgid
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
.
|
Loading…
Reference in New Issue