Improve handling of invalid URIs in attachements
Change-Id: I6fbbb43c6e250c7041e59a55d6e62d3cbdc531b6
diff --git a/Changes b/Changes
index a7bd991..00aad71 100755
--- a/Changes
+++ b/Changes
@@ -7,6 +7,7 @@
manager and can therefore survive URL changes. (diewald)
- Add KorAP::XML::Krill and KorAP::XML::TEI to
Dockerfile. (diewald)
+ - Improve handling of invalid URIs in attachements. (diewald)
0.43 2021-11-05
- New menu class that has an entry at the very end,
diff --git a/dev/js/spec/matchSpec.js b/dev/js/spec/matchSpec.js
index 2a1b6b0..effe8d4 100644
--- a/dev/js/spec/matchSpec.js
+++ b/dev/js/spec/matchSpec.js
@@ -92,14 +92,20 @@
"@type": "koral:field",
"key": "xlink2",
"type": "type:attachement",
- "value": "data:application/x.korap-link;example=%20Das%20war%20einfach;title=Hallo%21,https%3A%2F%2Fwww.test.de"
+ "value" : "data:application/x.korap-link;example=%20Das%20war%20einfach;title=Hallo%21,https%3A%2F%2Fwww.test.de",
+ },
+ {
+ "@type": "koral:field",
+ "key": "xlink3",
+ "type": "type:attachement",
+ "value": "data:application/x.korap-link;title=Gingko-Webseite%20an%20der%20Universit%E4t%20Leipzig,http%3A%2F%2Fwww.uni-leipzig.de%2Fgingko%2F"
},
{
"@type": "koral:field",
"key": "z-reference",
"type": "type:attachement",
"value": "data:,This is a reference"
- }
+ },
];
@@ -927,12 +933,18 @@
expect(mel.children[4].children[1].firstChild.textContent).toEqual('Hallo!');
expect(mel.children[4].children[1].firstChild.tagName).toEqual('A');
expect(mel.children[4].children[1].firstChild.getAttribute('href')).toEqual('https://www.test.de');
-
+
//type:attachement with plain text
expect(mel.children[5].children[1].getAttribute('data-type')).toEqual('type:attachement')
expect(mel.children[5].children[1].classList.contains('metakeyvalues')).toBeFalsy;
- expect(mel.children[5].children[0].firstChild.nodeValue).toEqual('z-reference');
- expect(mel.children[5].children[1].firstChild.nodeValue).toEqual('This is a reference');
+ expect(mel.children[5].children[0].firstChild.nodeValue).toEqual('xlink3');
+ expect(mel.children[5].children[1].firstChild.nodeValue).toEqual('[INVALID URI]');
+
+ //type:attachement with plain text
+ expect(mel.children[6].children[1].getAttribute('data-type')).toEqual('type:attachement')
+ expect(mel.children[6].children[1].classList.contains('metakeyvalues')).toBeFalsy;
+ expect(mel.children[6].children[0].firstChild.nodeValue).toEqual('z-reference');
+ expect(mel.children[6].children[1].firstChild.nodeValue).toEqual('This is a reference');
});
diff --git a/dev/js/src/match/attachement.js b/dev/js/src/match/attachement.js
index 70a2a20..45c4b21 100644
--- a/dev/js/src/match/attachement.js
+++ b/dev/js/src/match/attachement.js
@@ -29,8 +29,18 @@
_init : function (url) {
const t = this;
+ t.base64 = false;
+ t.isLink = false;
+ t.contentType = "text/plain";
+
// Decode
- url = decodeURIComponent(url);
+ var url;
+ try {
+ url = decodeURIComponent(url);
+ } catch (e) {
+ t.payload = '[INVALID URI]';
+ return t;
+ }
if (!uriRE.exec(url))
return;
@@ -39,9 +49,6 @@
let map = {};
let start = 0;
- t.base64 = false;
- t.isLink = false;
- t.contentType = "text/plain";
// Split parameter map
RegExp.$1.split(/ *; */).map(function (item) {