From f990d5ac870bb83b8ca7df374959af5c23ee6d01 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Wed, 2 Feb 2022 12:29:19 +0100 Subject: [PATCH] fix rendering of html of keepright issues --- modules/services/keepRight.js | 12 ++++++------ modules/ui/keepRight_details.js | 4 ++-- modules/ui/keepRight_header.js | 11 ++++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/services/keepRight.js b/modules/services/keepRight.js index 375256550..927728224 100644 --- a/modules/services/keepRight.js +++ b/modules/services/keepRight.js @@ -2,6 +2,7 @@ import RBush from 'rbush'; import { dispatch as d3_dispatch } from 'd3-dispatch'; import { json as d3_json } from 'd3-fetch'; +import { unescape } from 'lodash-es'; import { fileFetcher } from '../core/file_fetcher'; import { geoExtent, geoVecAdd } from '../geo'; @@ -65,7 +66,6 @@ function updateRtree(item, replace) { function tokenReplacements(d) { if (!(d instanceof QAItem)) return; - const htmlRegex = new RegExp(/<\/[a-z][\s\S]*>/); const replacements = {}; const issueTemplate = _krData.errorTypes[d.whichType]; @@ -99,12 +99,12 @@ function tokenReplacements(d) { idType = 'IDs' in issueTemplate ? issueTemplate.IDs[i-1] : ''; if (idType && capture) { // link IDs if present in the capture capture = parseError(capture, idType); - } else if (htmlRegex.test(capture)) { // escape any html in non-IDs - capture = '\\' + capture + '\\'; } else { const compare = capture.toLowerCase(); if (_krData.localizeStrings[compare]) { // some replacement strings can be localized capture = t('QA.keepRight.error_parts.' + _krData.localizeStrings[compare]); + } else { + capture = unescape(capture); } } @@ -160,15 +160,15 @@ function parseError(capture, idType) { function linkErrorObject(d) { - return `${d}`; + return { html: `${d}` }; } function linkEntity(d) { - return `${d}`; + return { html: `${d}` }; } function linkURL(d) { - return `${d}`; + return { html: `${d}` }; } // arbitrary node list of form: #ID, #ID, #ID... diff --git a/modules/ui/keepRight_details.js b/modules/ui/keepRight_details.js index 2adf77cdb..6045ff664 100644 --- a/modules/ui/keepRight_details.js +++ b/modules/ui/keepRight_details.js @@ -14,12 +14,12 @@ export function uiKeepRightDetails(context) { function issueDetail(d) { const { itemType, parentIssueType } = d; - const unknown = t.html('inspector.unknown'); + const unknown = { html: t.html('inspector.unknown') }; let replacements = d.replacements || {}; replacements.default = unknown; // special key `default` works as a fallback string let detail = t.html(`QA.keepRight.errorTypes.${itemType}.description`, replacements); - if (detail === unknown) { + if (detail === unknown.html) { detail = t.html(`QA.keepRight.errorTypes.${parentIssueType}.description`, replacements); } return detail; diff --git a/modules/ui/keepRight_header.js b/modules/ui/keepRight_header.js index b966b2fe1..91230849c 100644 --- a/modules/ui/keepRight_header.js +++ b/modules/ui/keepRight_header.js @@ -10,13 +10,14 @@ export function uiKeepRightHeader() { const { itemType, parentIssueType } = d; const unknown = t.html('inspector.unknown'); let replacements = d.replacements || {}; - replacements.default = unknown; // special key `default` works as a fallback string + replacements.default = { html: unknown }; // special key `default` works as a fallback string - let title = t.html(`QA.keepRight.errorTypes.${itemType}.title`, replacements); - if (title === unknown) { - title = t.html(`QA.keepRight.errorTypes.${parentIssueType}.title`, replacements); + const title = t.html(`QA.keepRight.errorTypes.${itemType}.title`, replacements); + if (title !== unknown) { + return t.apply(`QA.keepRight.errorTypes.${itemType}.title`, replacements); + } else { + return t.apply(`QA.keepRight.errorTypes.${parentIssueType}.title`, replacements); } - return title; }