X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/7407e4e31f358e152ac2ec96e0ba964a42f54a99..3556e5483957f8479c5747e36c626e91a655cc21:/src/common/xml.ts diff --git a/src/common/xml.ts b/src/common/xml.ts index 098f2781..e7db3aca 100644 --- a/src/common/xml.ts +++ b/src/common/xml.ts @@ -2,7 +2,28 @@ // // SPDX-License-Identifier: AGPL-3.0 -export const getTagValue = (document: Document | Element, tagName: string, defaultValue: string) => { +import { customDecodeURI } from "./url"; + +export const getTagValue = (document: Document | Element, tagName: string, defaultValue: string, skipDecoding: boolean = false) => { const [el] = Array.from(document.getElementsByTagName(tagName)); - return decodeURI(el ? el.innerHTML : defaultValue); + const URI = el ? htmlDecode(el.innerHTML) : defaultValue; + + if (!skipDecoding) { + try { + return customDecodeURI(URI); + } catch(e) {} + } + + return URI; +}; + +const htmlDecode = (input: string) => { + const out = input.split(' ').map((i) => { + const doc = new DOMParser().parseFromString(i, "text/html"); + if (doc.documentElement !== null) { + return doc.documentElement.textContent || ''; + } + return ''; + }); + return out.join(' '); };