15685: Fixes file name encoding/decoding handling on webdav.
[arvados-workbench2.git] / src / common / xml.ts
index 098f27818a85c6406445f08770231909ea400c62..3c6feb5dce8836a92a08074ba32a768af4ec84fc 100644 (file)
@@ -4,5 +4,16 @@
 
 export const getTagValue = (document: Document | Element, tagName: string, defaultValue: string) => {
     const [el] = Array.from(document.getElementsByTagName(tagName));
-    return decodeURI(el ? el.innerHTML : defaultValue);
+    return decodeURI(el ? htmlDecode(el.innerHTML) : defaultValue);
+};
+
+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(' ');
 };