Skip to content

Commit

Permalink
Adding a warning icon for ZIP files with invalid entry names.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Dec 16, 2024
1 parent 6e1fcf8 commit 81142fd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
19 changes: 17 additions & 2 deletions src/components/Solutions/SolutionFiles/SolutionFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import ResourceRenderer from '../../helpers/ResourceRenderer';
import Callout from '../../widgets/Callout';
import Button, { TheButtonGroup } from '../../widgets/TheButton';
import Box from '../../widgets/Box';
import Icon, { CodeFileIcon, DownloadIcon, ZipIcon } from '../../icons';
import Icon, { CodeFileIcon, DownloadIcon, WarningIcon, ZipIcon } from '../../icons';
import { prettyPrintBytes } from '../../helpers/stringFormatters.js';

const nameComparator = (a, b) => a.name.localeCompare(b.name, 'en');

const preprocessZipEntries = ({ zipEntries, ...file }) => {
if (zipEntries) {
file.zipEntriesBadNames = zipEntries.reduce((bad, { name }) => bad || name.includes('\\'), false);
file.zipEntries = zipEntries
.filter(({ name, size }) => !(name.endsWith('/') || name.endsWith('\\')) || size !== 0)
.map(({ name, size }) => ({ name, size, id: `${file.id}/${name}`, parentId: file.id }))
Expand Down Expand Up @@ -121,6 +122,20 @@ const SolutionFiles = ({
}>
{file.name}
</code>

{file.zipEntriesBadNames && (
<WarningIcon
gapLeft
className="text-danger"
tooltipId={`${file.id}-badEntries`}
tooltip={
<FormattedMessage
id="app.solutionFiles.badZipEntryNames"
defaultMessage="Some of the ZIP entry names are invalid."
/>
}
/>
)}
</td>
<td className="small text-nowrap">{prettyPrintBytes(file.size)}</td>

Expand Down Expand Up @@ -180,7 +195,7 @@ const SolutionFiles = ({
<FormattedMessage id="app.solutionFiles.total" defaultMessage="Total:" />
</em>
</td>
<td className="small text-body-secondary">
<td className="small text-body-secondary text-nowrap">
<em>{prettyPrintBytes(filesSize)}</em>
</td>
<td className="text-nowrap shrink-col text-end">
Expand Down
4 changes: 2 additions & 2 deletions src/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,6 @@
"app.logout": "Odhlásit",
"app.markdownTextArea.canUseMarkdown": "V tomto poli je povoleno používat <a>syntaxi markdown</a>.",
"app.markdownTextArea.empty": "Prázdné",
"app.markdownTextArea.preview": "Náhled:",
"app.markdownTextArea.showPreview": "Ukaž náhled",
"app.maybeBonusAssignmentIcon.isBonus": "Je bonusová",
"app.maybePublicIcon.visibleFrom": "Viditelná od {date}",
Expand Down Expand Up @@ -1851,6 +1850,7 @@
"app.solution.title": "Řešení",
"app.solutionArchiveInfoBox.description": "Všechny soubory v ZIPu",
"app.solutionDetail.comments.additionalSwitchNote": "(autor tohoto řešení a vedoucí této skupiny)",
"app.solutionFiles.badZipEntryNames": "Některé názvy položek v ZIP archivu nejsou platné.",
"app.solutionFiles.countLimitExceeded": "Celkový počet souborů řešení překročil výchozí limit ({limit}).",
"app.solutionFiles.downloadButton": "Stáhnout soubor",
"app.solutionFiles.entryPoint": "Vstupní bod (zaváděcí soubor aplikace)",
Expand Down Expand Up @@ -2184,4 +2184,4 @@
"recodex-judge-shuffle-all": "Sudí neuspořádaných tokenů a řádků",
"recodex-judge-shuffle-newline": "Sudí neuspořádaných tokenů (ignorující konce řádků)",
"recodex-judge-shuffle-rows": "Sudí neuspořádaných řádků"
}
}
2 changes: 1 addition & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,6 @@
"app.logout": "Logout",
"app.markdownTextArea.canUseMarkdown": "You can use <a>markdown syntax</a> in this field.",
"app.markdownTextArea.empty": "Empty",
"app.markdownTextArea.preview": "Preview:",
"app.markdownTextArea.showPreview": "Preview",
"app.maybeBonusAssignmentIcon.isBonus": "Is Bonus",
"app.maybePublicIcon.visibleFrom": "Visible from {date}",
Expand Down Expand Up @@ -1851,6 +1850,7 @@
"app.solution.title": "The Solution",
"app.solutionArchiveInfoBox.description": "All files in a ZIP archive",
"app.solutionDetail.comments.additionalSwitchNote": "(author of the solution and supervisors of this group)",
"app.solutionFiles.badZipEntryNames": "Some of the ZIP entry names are invalid.",
"app.solutionFiles.countLimitExceeded": "The total number of submitted files exceeds the default solution files limit ({limit}).",
"app.solutionFiles.downloadButton": "Download file",
"app.solutionFiles.entryPoint": "Execution entry point (bootstrap)",
Expand Down

0 comments on commit 81142fd

Please sign in to comment.