Buffer: Split only complete lines ending with \r\n

This change is required for Turtle output generated by the Python environment. Otherwise, drawing some images could add empty new lines (in the browser), since the original JSON message got split between the ending \r\n characters.
This commit is contained in:
Sebastian Serth
2023-09-20 22:33:59 +02:00
parent 1bba4a006a
commit b5cb5c16dd

View File

@ -6,7 +6,7 @@ class Runner::Connection::Buffer
# 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
SPLIT_INDIVIDUAL_LINES = /(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|[^\n])+/
SPLIT_INDIVIDUAL_LINES = /(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|(?:[^\r\n]|\r(?=\n)))+/
def initialize
@global_buffer = +''