X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/714e665e783490e3710a772bc54c2c062965e812..08ac60f877d6495a748747a3a0d30ca9f0e289d5:/src/common/xml.ts diff --git a/src/common/xml.ts b/src/common/xml.ts index c810de9570..e7db3acad8 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 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(' '); };