From 3d93f7f0fe641288bd988f0800e644f4ba0d2c72 Mon Sep 17 00:00:00 2001 From: peolic <66393006+peolic@users.noreply.github.com> Date: Tue, 25 May 2021 04:18:09 +0300 Subject: [PATCH] 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 --- .../src/components/Changelog/versions/v080.md | 3 ++- ui/v2.5/src/models/list-filter/filter.ts | 19 ++++++++++++------- ui/v2.5/src/models/list-filter/types.ts | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ui/v2.5/src/components/Changelog/versions/v080.md b/ui/v2.5/src/components/Changelog/versions/v080.md index d43c0190c..82b5ff5e4 100644 --- a/ui/v2.5/src/components/Changelog/versions/v080.md +++ b/ui/v2.5/src/components/Changelog/versions/v080.md @@ -5,11 +5,12 @@ * Added [DLNA server](/settings?tab=dlna). ([#1364](https://github.com/stashapp/stash/pull/1364)) ### 🎨 Improvements -* Add `CreatedAt` and `UpdatedAt` (and `FileModTime` where applicable) to API objects. +* Add `CreatedAt` and `UpdatedAt` (and `FileModTime` where applicable) to API objects. ([#1421](https://github.com/stashapp/stash/pull/1421)) * Add Studios Performer filter criterion. ([#1405](https://github.com/stashapp/stash/pull/1405)) * Add `subtractDays` post-process scraper action. ([#1399](https://github.com/stashapp/stash/pull/1399)) * Skip scanning directories if path matches image and video exclude patterns. ([#1382](https://github.com/stashapp/stash/pull/1382)) * Add button to remove studio stash ID. ([#1378](https://github.com/stashapp/stash/pull/1378)) ### 🐛 Bug fixes +* Fix quotes in filter labels causing UI errors. ([#1425](https://github.com/stashapp/stash/pull/1425)) * Fix post-processing not running when scraping by performer fragment. ([#1387](https://github.com/stashapp/stash/pull/1387)) diff --git a/ui/v2.5/src/models/list-filter/filter.ts b/ui/v2.5/src/models/list-filter/filter.ts index 6eb2d20e2..cd58b819c 100644 --- a/ui/v2.5/src/models/list-filter/filter.ts +++ b/ui/v2.5/src/models/list-filter/filter.ts @@ -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); } }); } diff --git a/ui/v2.5/src/models/list-filter/types.ts b/ui/v2.5/src/models/list-filter/types.ts index 4507b63eb..02be2c476 100644 --- a/ui/v2.5/src/models/list-filter/types.ts +++ b/ui/v2.5/src/models/list-filter/types.ts @@ -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) }; }