From e34656eb0fb45de133132cfd50e7fddeb1ecfe0a Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Mon, 15 Nov 2021 00:30:32 +0100 Subject: [PATCH] Modify buffer line breaking behavior * This is based on Sentry issue CODEOCEAN-5W (linter translation failing due to \r in output) * We cannot keep all "\r" messages but we must not forward the "\r" if it is a single message received after a valid JSON --- lib/runner/connection/buffer.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/runner/connection/buffer.rb b/lib/runner/connection/buffer.rb index cf8ca6fc..7a1b3af5 100644 --- a/lib/runner/connection/buffer.rb +++ b/lib/runner/connection/buffer.rb @@ -71,8 +71,8 @@ class Runner::Connection::Buffer @buffering = false @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") unless message.length == 1 + # Thus, we now re-add the `\n` at the end of the string and remove the `\r` at the same time. + message = message.gsub(/\r$/, "\n") @line_buffer.push message end @@ -83,10 +83,10 @@ class Runner::Connection::Buffer invalid_json = !valid_json?(message) # Second, if we have the beginning of a valid command but an invalid JSON return true if invalid_json && message.start_with?(/\s*{"cmd/) - # Third, global_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.include?('