Connection Buffer: Replace \r in run and score output with \n

This commit is contained in:
Sebastian Serth
2021-10-31 14:34:55 +01:00
parent 1e7cf1c622
commit 6ff14d6fc7
2 changed files with 5 additions and 2 deletions

View File

@ -175,7 +175,6 @@ CodeOceanEditorEvaluation = {
if (!msg.data || msg.data === "\r") { if (!msg.data || msg.data === "\r") {
return; return;
} }
msg.data = msg.data.replace(/(\r)/gm, "\n");
var stream = {}; var stream = {};
stream[msg.stream] = msg.data; stream[msg.stream] = msg.data;
this.printOutput(stream, true, 0); this.printOutput(stream, true, 0);

View File

@ -3,7 +3,8 @@
class Runner::Connection::Buffer class Runner::Connection::Buffer
# The WebSocket connection might group multiple lines. For further processing, we require all lines # The WebSocket connection might group multiple lines. For further processing, we require all lines
# to be processed separately. Therefore, we split the lines by each newline character not part of an enclosed # to be processed separately. Therefore, we split the lines by each newline character not part of an enclosed
# substring either in single or double quotes (e.g., within a JSON) # substring either in single or double quotes (e.g., within a JSON). Originally, each line break consists of `\r\n`.
# We keep the `\r` at the end of the line (keeping "empty" lines) and replace it after buffering.
# Inspired by https://stackoverflow.com/questions/13040585/split-string-by-spaces-properly-accounting-for-quotes-and-backslashes-ruby # Inspired by https://stackoverflow.com/questions/13040585/split-string-by-spaces-properly-accounting-for-quotes-and-backslashes-ruby
SPLIT_INDIVIDUAL_LINES = Regexp.compile(/(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|[^\n])+/) SPLIT_INDIVIDUAL_LINES = Regexp.compile(/(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|[^\n])+/)
@ -69,6 +70,9 @@ class Runner::Connection::Buffer
def add_to_line_buffer(message) def add_to_line_buffer(message)
@buffering = false @buffering = false
@global_buffer = +'' @global_buffer = +''
# For our buffering, we identified line breaks with the `\n` and removed those temporarily.
# Thus, we now re-add the `\n` at the end of the string and remove the `\r` in the same time.
message = message.gsub(/\r$/, "\n")
@line_buffer.push message @line_buffer.push message
end end