Connection::Buffer: Restore buffering for lines ending with CR
With the turtle graphics, some very long lines might be returned by Poseidon just after the CR (\r). In this case, our new normalization will fix the mistake, but the next message received (just a LF `\n`) will be forwarded to the clients unchanged. This is not desired, so that we filter this case separately.
This commit is contained in:
@ -74,7 +74,16 @@ class Runner::Connection::Buffer
|
|||||||
# First, we ensure line endings are only represented by `\n`, regardless of the original line ending.
|
# First, we ensure line endings are only represented by `\n`, regardless of the original line ending.
|
||||||
# Then, we convert all line endings to `\r\n` to ensure we can identify the `\r` at the end of a line.
|
# Then, we convert all line endings to `\r\n` to ensure we can identify the `\r` at the end of a line.
|
||||||
# This "double conversion" is required to prevent line endings with \r\r\n.
|
# This "double conversion" is required to prevent line endings with \r\r\n.
|
||||||
string.encode(universal_newline: true).encode(crlf_newline: true)
|
normalized = string.encode(universal_newline: true).encode(crlf_newline: true)
|
||||||
|
|
||||||
|
# If the original input string ends with `\r`, it is incomplete and needs buffering.
|
||||||
|
# However, through our above normalization, the string would not end with `\r` anymore (but `\r\n`).
|
||||||
|
# Hence, in this case, we just remove the last character, so that all other line endings within the string remain unchanged.
|
||||||
|
if string.ends_with?("\r")
|
||||||
|
normalized[...-1]
|
||||||
|
else
|
||||||
|
normalized
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_to_line_buffer(message)
|
def add_to_line_buffer(message)
|
||||||
|
Reference in New Issue
Block a user