Skip to content

Commit

Permalink
Fix bug when showing links in the result table (#65)
Browse files Browse the repository at this point in the history
In the file `backernd/static/js/helper.js` the line `link = cpy.match(/(https?:\/\/[a-zA-Z0-9.:%/#\?_-]+)/g)[0];` led to issues with results of the `encode_for_uri` function (see ad-freiburg/qlever#1128), because of a missing check if the `.match()` function actually finds any result.
  • Loading branch information
hannahbast authored Nov 24, 2023
2 parents 14cc93a + 7b1d7c8 commit a574e46
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions backend/static/js/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,20 +960,23 @@ function getFormattedResultEntry(str, maxLength, column = undefined) {
//
// TODO: What if http occur somewhere inside a literal or a link?
} else if (pos_http > 0) {
isLink = true;
cpy = cpy.replace(/ /g, '_');
link = cpy.match(/(https?:\/\/[a-zA-Z0-9.:%/#\?_-]+)/g)[0];
checkLink = link.toLowerCase();
if (checkLink.endsWith('jpg') || checkLink.endsWith('png') || checkLink.endsWith('gif') || checkLink.endsWith('jpeg') || checkLink.endsWith('svg')) {
str = "";
linkStart = '<a href="' + link + '" target="_blank"><img src="' + link + '" width="50" >';
linkEnd = '</a>';
} else if (checkLink.endsWith('pdf') || checkLink.endsWith('doc') || checkLink.endsWith('docx')) {
linkStart = '<span style="white-space: nowrap;"><a href="' + link + '" target="_blank"><i class="glyphicon glyphicon-file"></i>&nbsp;';
linkEnd = '</a></span>';
} else {
linkStart = '<span style="white-space: nowrap;"><a href="' + link + '" target="_blank"><i class="glyphicon glyphicon-link"></i>&nbsp;';
linkEnd = '</a></span>';
link_match = cpy.match(/(https?:\/\/[a-zA-Z0-9.:%/#\?_-]+)/g);
if(link_match != null) {
isLink = true;
link = link_match[0];
checkLink = link.toLowerCase();
if (checkLink.endsWith('jpg') || checkLink.endsWith('png') || checkLink.endsWith('gif') || checkLink.endsWith('jpeg') || checkLink.endsWith('svg')) {
str = "";
linkStart = '<a href="' + link + '" target="_blank"><img src="' + link + '" width="50" >';
linkEnd = '</a>';
} else if (checkLink.endsWith('pdf') || checkLink.endsWith('doc') || checkLink.endsWith('docx')) {
linkStart = '<span style="white-space: nowrap;"><a href="' + link + '" target="_blank"><i class="glyphicon glyphicon-file"></i>&nbsp;';
linkEnd = '</a></span>';
} else {
linkStart = '<span style="white-space: nowrap;"><a href="' + link + '" target="_blank"><i class="glyphicon glyphicon-link"></i>&nbsp;';
linkEnd = '</a></span>';
}
}
}

Expand Down

0 comments on commit a574e46

Please sign in to comment.