Skip to content

Commit

Permalink
Improve detection of binary file encoding when editing executables.
Browse files Browse the repository at this point in the history
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 DOMjudge#1526.
  • Loading branch information
meisterT committed Apr 17, 2022
1 parent 80d6ea5 commit 404ca77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions webapp/src/Controller/Jury/ExecutableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions webapp/templates/jury/executable_content.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<h1>View content of executable {{ executable.execid }}</h1>

{% if skippedBinary is not empty %}
<div>
Binary files:
<div class="alert alert-warning">
We exclude these files from editing since we could not detect their encoding (e.g. they are binary files):
<ul>
{% for file in skippedBinary %}
<li>{{ file }}</li>
<li><code>{{ file }}</code></li>
{% endfor %}
</ul>
</div>
Expand Down

0 comments on commit 404ca77

Please sign in to comment.