Skip to content

Commit

Permalink
Fix importing of files using relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Jan 28, 2017
1 parent a33c53d commit 4d56191
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chrome/content/zotero/xpcom/translation/translate_item.js
Expand Up @@ -57,7 +57,7 @@ Zotero.Translate.ItemSaver = function(options) {
this._proxy = options.proxy;

// the URI to which other URIs are assumed to be relative
if(typeof baseURI === "object" && baseURI instanceof Components.interfaces.nsIURI) {
if(typeof options.baseURI === "object" && options.baseURI instanceof Components.interfaces.nsIURI) {
this._baseURI = options.baseURI;
} else {
// try to convert to a URI
Expand Down
39 changes: 39 additions & 0 deletions test/tests/translateTest.js
Expand Up @@ -597,6 +597,45 @@ describe("Zotero.Translate", function() {
});
});


describe("Translators", function () {
it("should round-trip child attachment via BibTeX", function* () {
var item = yield createDataObject('item');
yield importFileAttachment('test.png', { parentItemID: item.id });

var translation = new Zotero.Translate.Export();
var tmpDir = yield getTempDirectory();
var exportDir = OS.Path.join(tmpDir, 'export');
translation.setLocation(Zotero.File.pathToFile(exportDir));
translation.setItems([item]);
translation.setTranslator("9cb70025-a888-4a29-a210-93ec52da40d4");
translation.setDisplayOptions({
exportFileData: true
});
yield translation.translate();

var exportFile = OS.Path.join(exportDir, 'export.bib');
assert.isTrue(yield OS.File.exists(exportFile));

var translation = new Zotero.Translate.Import();
translation.setLocation(Zotero.File.pathToFile(exportFile));
var translators = yield translation.getTranslators();
translation.setTranslator(translators[0]);
var importCollection = yield createDataObject('collection');
var items = yield translation.translate({
libraryID: Zotero.Libraries.userLibraryID,
collections: [importCollection.id]
});

assert.lengthOf(items, 1);
var attachments = items[0].getAttachments();
assert.lengthOf(attachments, 1);
var attachment = Zotero.Items.get(attachments[0]);
assert.isTrue(yield attachment.fileExists());
});
});


describe("ItemSaver", function () {
describe("#saveCollections()", function () {
it("should add top-level collections to specified collection", function* () {
Expand Down

0 comments on commit 4d56191

Please sign in to comment.