From 404ca77cb01d125c4c4ed85f079e511c85a7278a Mon Sep 17 00:00:00 2001 From: Tobias Werth Date: Sun, 17 Apr 2022 15:59:30 +0200 Subject: [PATCH] Improve detection of binary file encoding when editing executables. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This now allows to have non-ASCII characters as `ąśćżźć` to not trigger false positives. Also show a nicer alert message while we are changing this code. Part of #1526. --- webapp/src/Controller/Jury/ExecutableController.php | 4 ++-- webapp/templates/jury/executable_content.html.twig | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/webapp/src/Controller/Jury/ExecutableController.php b/webapp/src/Controller/Jury/ExecutableController.php index 3af01378d8..da9200734f 100644 --- a/webapp/src/Controller/Jury/ExecutableController.php +++ b/webapp/src/Controller/Jury/ExecutableController.php @@ -413,9 +413,9 @@ protected function dataForEditor(Executable $executable): array /** @var ExecutableFile $file */ $filename = $file->getFilename(); $content = $file->getFileContent(); - if (!mb_check_encoding($content, 'ASCII')) { + if (!mb_detect_encoding($content, null, true)) { $skippedBinary[] = $filename; - continue; // skip binary files + continue; // Skip binary files. } $filenames[] = $filename; $file_contents[] = $content; diff --git a/webapp/templates/jury/executable_content.html.twig b/webapp/templates/jury/executable_content.html.twig index fcc74576a8..e1dbe4eddb 100644 --- a/webapp/templates/jury/executable_content.html.twig +++ b/webapp/templates/jury/executable_content.html.twig @@ -13,11 +13,11 @@

View content of executable {{ executable.execid }}

{% if skippedBinary is not empty %} -
- Binary files: +
+ We exclude these files from editing since we could not detect their encoding (e.g. they are binary files):
    {% for file in skippedBinary %} -
  • {{ file }}
  • +
  • {{ file }}
  • {% endfor %}