Fix invalid scene queue generated link (#1425)

* Escape quotes in criterion label

JSON encoding and slicing off the encompassing JSON-string quotes seems like a safer option

* Wrap criterion parse in try/catch

to prevent the page from crashing
This commit is contained in:
peolic
2021-05-25 04:18:09 +03:00
committed by GitHub
parent 5c4351f338
commit 3d93f7f0fe
3 changed files with 16 additions and 10 deletions

View File

@@ -425,13 +425,18 @@ export class ListFilterModel {
}
jsonParameters.forEach((jsonString) => {
const encodedCriterion = JSON.parse(jsonString);
const criterion = makeCriteria(encodedCriterion.type);
// it's possible that we have unsupported criteria. Just skip if so.
if (criterion) {
criterion.value = encodedCriterion.value;
criterion.modifier = encodedCriterion.modifier;
this.criteria.push(criterion);
try {
const encodedCriterion = JSON.parse(jsonString);
const criterion = makeCriteria(encodedCriterion.type);
// it's possible that we have unsupported criteria. Just skip if so.
if (criterion) {
criterion.value = encodedCriterion.value;
criterion.modifier = encodedCriterion.modifier;
this.criteria.push(criterion);
}
} catch (err) {
// eslint-disable-next-line no-console
console.error("Failed to parse encoded criterion:", err);
}
});
}

View File

@@ -29,8 +29,8 @@ export interface ILabeledValue {
}
export function encodeILabeledId(o: ILabeledId) {
// escape \ to \\ so that it encodes to JSON correctly
const adjustedLabel = o.label.replaceAll("\\", "\\\\");
// escape " and \ and by encoding to JSON so that it encodes to JSON correctly down the line
const adjustedLabel = JSON.stringify(o.label).slice(1, -1);
return { ...o, label: encodeURIComponent(adjustedLabel) };
}