Connection::Buffer: Ignore comments for quote matching

Within a source code comment (beginning with # or \\), a user could write arbitrary text, including unmatched quotes " or '. This is not an error and should be supported. However, with the current implementation, we would also treat such a quote the same way as an original one. With this commit, we fix that erroneous behavior.

Fixes CODEOCEAN-XF
This commit is contained in:
Sebastian Serth
2023-09-30 16:33:41 +02:00
parent 651d56932c
commit 42b0507cd6

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`. # 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. # 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 = /(?:"""(?:\\"|[^"])*"""|"(?!"")(?:\\"|[^"])*"|''(?:\\'|[^'])*'''|'(?!'')(?:\\'|[^'])*'|(?:[^\r\n]|\r(?=\n)))+/ SPLIT_INDIVIDUAL_LINES = /(?:"""(?:\\"|[^"])*"""|"(?!"")(?:\\"|[^"])*"|''(?:\\'|[^'])*'''|'(?!'')(?:\\'|[^'])*'|[#\\][^\r\n]*|(?:[^\r\n]|\r(?=\n)))+/
def initialize def initialize
@global_buffer = +'' @global_buffer = +''