Don't return relative path from .attachmentFilename for linked files
https://forums.zotero.org/discussion/86139/zotero-item-attachmentfilename-should-only-return-filename
This commit is contained in:
parent
d5ac87648b
commit
b0e065a4ae
2 changed files with 38 additions and 11 deletions
|
@ -2839,7 +2839,7 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentFilename', {
|
|||
}
|
||||
var prefixedPath = path.match(/^(?:attachments|storage):(.*)$/);
|
||||
if (prefixedPath) {
|
||||
return prefixedPath[1];
|
||||
return prefixedPath[1].split('/').pop();
|
||||
}
|
||||
return OS.Path.basename(path);
|
||||
},
|
||||
|
|
|
@ -895,6 +895,11 @@ describe("Zotero.Item", function () {
|
|||
})
|
||||
|
||||
describe("#attachmentFilename", function () {
|
||||
afterEach(function () {
|
||||
Zotero.Prefs.set('saveRelativeAttachmentPath', false)
|
||||
Zotero.Prefs.clear('baseAttachmentPath')
|
||||
});
|
||||
|
||||
it("should get and set a filename for a stored file", function* () {
|
||||
var filename = "test.txt";
|
||||
|
||||
|
@ -925,12 +930,42 @@ describe("Zotero.Item", function () {
|
|||
assert.equal(item.getFilePath(), file.path);
|
||||
});
|
||||
|
||||
it.skip("should get and set a filename for a base-dir-relative file", function* () {
|
||||
it("should get a filename for a base-dir-relative file", function () {
|
||||
var dir = getTestDataDirectory().path;
|
||||
Zotero.Prefs.set('saveRelativeAttachmentPath', true)
|
||||
Zotero.Prefs.set('baseAttachmentPath', dir)
|
||||
|
||||
})
|
||||
var file = OS.Path.join(dir, 'test.png');
|
||||
|
||||
var item = new Zotero.Item('attachment');
|
||||
item.attachmentLinkMode = 'linked_file';
|
||||
item.attachmentPath = file;
|
||||
|
||||
assert.equal(item.attachmentFilename, 'test.png');
|
||||
});
|
||||
|
||||
it("should get a filename for a base-dir-relative file in a subdirectory", function () {
|
||||
var dir = getTestDataDirectory().path;
|
||||
var baseDir = OS.Path.dirname(dir);
|
||||
Zotero.Prefs.set('saveRelativeAttachmentPath', true)
|
||||
Zotero.Prefs.set('baseAttachmentPath', baseDir)
|
||||
|
||||
var file = OS.Path.join(dir, 'test.png');
|
||||
|
||||
var item = new Zotero.Item('attachment');
|
||||
item.attachmentLinkMode = 'linked_file';
|
||||
item.attachmentPath = file;
|
||||
|
||||
assert.equal(item.attachmentFilename, 'test.png');
|
||||
});
|
||||
})
|
||||
|
||||
describe("#attachmentPath", function () {
|
||||
afterEach(function () {
|
||||
Zotero.Prefs.set('saveRelativeAttachmentPath', false)
|
||||
Zotero.Prefs.clear('baseAttachmentPath')
|
||||
});
|
||||
|
||||
it("should return an absolute path for a linked attachment", function* () {
|
||||
var file = getTestDataDirectory();
|
||||
file.append('test.png');
|
||||
|
@ -948,7 +983,6 @@ describe("Zotero.Item", function () {
|
|||
|
||||
it("should set a prefixed relative path for a path within the defined base directory", function* () {
|
||||
var dir = getTestDataDirectory().path;
|
||||
var dirname = OS.Path.basename(dir);
|
||||
var baseDir = OS.Path.dirname(dir);
|
||||
Zotero.Prefs.set('saveRelativeAttachmentPath', true)
|
||||
Zotero.Prefs.set('baseAttachmentPath', baseDir)
|
||||
|
@ -960,14 +994,10 @@ describe("Zotero.Item", function () {
|
|||
item.attachmentPath = file;
|
||||
|
||||
assert.equal(item.attachmentPath, "attachments:data/test.png");
|
||||
|
||||
Zotero.Prefs.set('saveRelativeAttachmentPath', false)
|
||||
Zotero.Prefs.clear('baseAttachmentPath')
|
||||
})
|
||||
|
||||
it("should return a prefixed path for a linked attachment within the defined base directory", function* () {
|
||||
var dir = getTestDataDirectory().path;
|
||||
var dirname = OS.Path.basename(dir);
|
||||
var baseDir = OS.Path.dirname(dir);
|
||||
Zotero.Prefs.set('saveRelativeAttachmentPath', true)
|
||||
Zotero.Prefs.set('baseAttachmentPath', baseDir)
|
||||
|
@ -979,9 +1009,6 @@ describe("Zotero.Item", function () {
|
|||
});
|
||||
|
||||
assert.equal(item.attachmentPath, "attachments:data/test.png");
|
||||
|
||||
Zotero.Prefs.set('saveRelativeAttachmentPath', false)
|
||||
Zotero.Prefs.clear('baseAttachmentPath')
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue