Skip to content

Commit

Permalink
Force tags to be lowercase in the frontend during parsing
Browse files Browse the repository at this point in the history
The backend already enforces lowercase of the tags, but the frontend did not.
This could result in double challenge imports if you parse again.
Now after the custom parser, all tags are forced to be lower case and unique.

This fixes #89
  • Loading branch information
JJ-8 committed Mar 24, 2024
1 parent 49791e1 commit 80e463b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions front/src/components/Dialogs/TaskImportDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,29 +175,33 @@ export default defineComponent({
onPaste() {
void this.$nextTick(() => this.autoDetectParser());
},
normalizeTags(tags: string[]): string[] {
if (tags.length == 0) return [];
return Array.from(new Set(tags.map((t) => t.trim().toLowerCase())));
},
parseTasks(v: string): ParsedTask[] {
// Get list of task {title,category} from parse
const parsedTasks = this.currentParser.value.parse(v);
// Precompute a set of task to avoid N square operation
const hashTask = (title: string, tags: string[]): string =>
title +
tags
.map((t) => t.toLowerCase())
.sort()
.join('');
title + this.normalizeTags(tags).sort().join('');
const taskSet = new Set();
for (const task of this.ctf.tasks) {
taskSet.add(
hashTask(
task.title,
task.assignedTags.map((t) => t.tag)
this.normalizeTags(task.assignedTags.map((t) => t.tag))
)
);
}
// mark already existing tasks
return parsedTasks.map((task) => {
const hash = hashTask(task.title, task.tags);
return { ...task, keep: !taskSet.has(hash) };
return {
...task,
tags: this.normalizeTags(task.tags),
keep: !taskSet.has(hash),
};
});
},
computeTags(tags: { nodeId: number; tag: string }[]) {
Expand Down

0 comments on commit 80e463b

Please sign in to comment.