Buffer: Buffer messages with incomplete quotes

If a non-JSON message received contains quotes and is cut off weirdly, the following message might "quote" the line breaks. Then, we have an issue and cause \r\n\n for the further processing within the CodeOcean backend.
This commit is contained in:
Sebastian Serth
2023-09-20 22:35:26 +02:00
parent b5cb5c16dd
commit 03637b3185

View File

@ -88,6 +88,8 @@ class Runner::Connection::Buffer
return true if invalid_json && message.start_with?(/\s*{"cmd/) return true if invalid_json && message.start_with?(/\s*{"cmd/)
# Third, buffer the message if it contains long messages (e.g., an image or turtle batch commands) # Third, buffer the message if it contains long messages (e.g., an image or turtle batch commands)
return true if invalid_json && (message.start_with?('<img') || message.include?('"turtlebatch"')) return true if invalid_json && (message.start_with?('<img') || message.include?('"turtlebatch"'))
# Fourth, if we have an odd number of quotes and no `\r` at the end, we might have an incomplete message
return true if (message.count('"').odd? || message.count("'").odd?) && !message.end_with?("\r")
# If nothing applies, we don't want to buffer the current message # If nothing applies, we don't want to buffer the current message
false false