[sec] remove apostrophes from keys

This commit is contained in:
Avris 2021-08-11 23:12:55 +02:00
parent 8f51cda81e
commit 5019ef3f41
3 changed files with 9 additions and 4 deletions

View File

@ -1,7 +1,7 @@
import { Router } from 'express';
import SQL from "sql-template-strings";
import {ulid} from "ulid";
import {handleErrorAsync} from "../../src/helpers";
import {clearKey, handleErrorAsync} from "../../src/helpers";
const approve = async (db, id) => {
const { base_id } = await db.get(SQL`SELECT base_id FROM sources WHERE id=${id}`);
@ -84,7 +84,7 @@ router.post('/sources/submit', handleErrorAsync(async (req, res) => {
${id}, ${global.config.locale}, ${req.body.pronouns.join(';')},
${req.body.type}, ${req.body.author}, ${req.body.title}, ${req.body.extra}, ${req.body.year},
${req.body.fragments.join('@').replace(/\n/g, '|')}, ${req.body.comment}, ${req.body.link},
${req.body.key || null}, ${req.body.images || null},
${clearKey(req.body.key)}, ${req.body.images || null},
${req.user ? req.user.id : null}, ${req.body.base}
)
`);

View File

@ -1,7 +1,7 @@
import { Router } from 'express';
import SQL from 'sql-template-strings';
import {ulid} from "ulid";
import {isTroll, handleErrorAsync, sortClearedLinkedText} from "../../src/helpers";
import {isTroll, handleErrorAsync, sortClearedLinkedText, clearKey} from "../../src/helpers";
import { caches } from "../../src/cache";
const approve = async (db, id) => {
@ -95,7 +95,7 @@ router.post('/terms/submit', handleErrorAsync(async (req, res) => {
INSERT INTO terms (id, term, original, key, definition, approved, base_id, locale, author_id, category, flags, images)
VALUES (
${id},
${req.body.term.join('|')}, ${req.body.original.join('|')}, ${req.body.key || null}, ${req.body.definition},
${req.body.term.join('|')}, ${req.body.original.join('|')}, ${clearKey(req.body.key)}, ${req.body.definition},
0, ${req.body.base}, ${global.config.locale}, ${req.user ? req.user.id : null},
${req.body.categories.join(',')}, ${JSON.stringify(req.body.flags)}, ${req.body.images}
)

View File

@ -207,3 +207,8 @@ export const sortClearedLinkedText = (items, key) => {
items.sort((a, b) => clearLinkedText(a[key].toLowerCase()).localeCompare(clearLinkedText(b[key].toLowerCase())))
return items;
}
export const clearKey = (key) => {
if (!key) { return null; }
return key.replace(/'/g, '_');
}