From 692cb1107e24737a72bc4debd26129e6d724f2ba Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Thu, 7 Apr 2022 18:17:27 +0200 Subject: [PATCH] Remove non-printable characters from console --- app/assets/javascripts/editor/evaluation.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/assets/javascripts/editor/evaluation.js b/app/assets/javascripts/editor/evaluation.js index c5723f12..a94eae38 100644 --- a/app/assets/javascripts/editor/evaluation.js +++ b/app/assets/javascripts/editor/evaluation.js @@ -1,5 +1,8 @@ CodeOceanEditorEvaluation = { chunkBuffer: [{streamedResponse: true}], + // A list of non-printable characters that are not allowed in the code output. + // Taken from https://stackoverflow.com/a/69024306 + nonPrintableRegEx: /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u2000-\u200F\u2028-\u202F\u205F-\u206F\u3000\uFEFF]/g, /** * Scoring-Functions @@ -207,21 +210,28 @@ CodeOceanEditorEvaluation = { // Switch all four lines below to enable the output of images and render tags if (!colorize) { if (output.stdout !== undefined && output.stdout !== '') { + output.stdout = output.stdout.replace(this.nonPrintableRegEx, "") element.append(output.stdout) //element.text(element.text() + output.stdout) } if (output.stderr !== undefined && output.stderr !== '') { + output.stderr = output.stderr.replace(this.nonPrintableRegEx, "") + element.append('StdErr: ' + output.stderr); //element.text('StdErr: ' + element.text() + output.stderr); } } else if (output.stderr) { + output.stderr = output.stderr.replace(this.nonPrintableRegEx, "") + element.addClass('text-warning').append(output.stderr); //element.addClass('text-warning').text(element.text() + output.stderr); this.QaApiOutputBuffer.stderr += output.stderr; } else if (output.stdout) { + output.stdout = output.stdout.replace(this.nonPrintableRegEx, "") + element.addClass('text-success').append(output.stdout); //element.addClass('text-success').text(element.text() + output.stdout); this.QaApiOutputBuffer.stdout += output.stdout;