Commit 811ac6f0 authored by Robert Knight's avatar Robert Knight

Merge pull request #2570 from hypothesis/Kj8vWkme-show-filenames-of-local-files

Show filenames of local documents with titles
parents 8595292f 2072d9ae
......@@ -13,9 +13,18 @@ module.exports = function() {
*
*/
function documentDomainFilter(document) {
var uri = escapeHtml(document.uri || '');
var domain = escapeHtml(document.domain || '');
var title = escapeHtml(document.title || '');
if (uri.startsWith('file://') && title) {
var parts = uri.split('/');
var filename = parts[parts.length - 1];
if (filename) {
return '(' + filename + ')';
}
}
if (domain && domain !== title) {
return '(' + domain + ')';
} else {
......
......@@ -29,6 +29,15 @@ describe('documentDomain', function() {
assert(domain === '');
});
it('returns the filename for local documents with titles', function() {
var domain = documentDomainFilterProvider()({
title: 'example.com',
uri: 'file:///home/seanh/MyFile.pdf'
});
assert(domain === '(MyFile.pdf)');
});
it('escapes HTML in the document domain', function() {
var spamLink = '<a href="http://example.com/rubies">Buy rubies!!!</a>';
......@@ -39,4 +48,15 @@ describe('documentDomain', function() {
assert(domain.indexOf(spamLink) === -1);
});
it('escapes HTML in the document uri', function() {
var spamLink = '<a href="http://example.com/rubies">Buy rubies!!!</a>';
var domain = documentDomainFilterProvider()({
title: 'title',
uri: 'file:///home/seanh/' + spamLink
});
assert(domain.indexOf(spamLink) === -1);
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment