Don't store unknown/invalid fields in Extra in non-strict mode

And fix a couple things for if we turn it back on

This code came along with the type/field handling overhaul, but I think
it was originally intended for handling unknown fields during sync
before we decided on strict mode, so it wasn't finished and causes
various problems [1]. It could still be useful for preserving fields
from translators before they're available on items, but the better fix
there is just to add the missing fields, so I'm not sure if we'll end up
needing it.

[1] https://groups.google.com/d/msg/zotero-dev/a1IPUJ2m_3s/hfmdK2P3BwAJ
This commit is contained in:
Dan Stillman 2019-10-18 03:20:18 -04:00
parent 5913c53509
commit 1710eb1c4b
4 changed files with 33 additions and 10 deletions

View file

@ -190,6 +190,12 @@ describe("Zotero.Utilities.Internal", function () {
assert.equal(extra, "Publisher Place: " + place2);
});
it("shouldn't extract a field from a line that begins with a whitespace", function () {
var str = '\n number-of-pages: 11';
var { fields, extra } = Zotero.Utilities.Internal.extractExtraFields(str);
assert.equal(fields.size, 0);
});
it("shouldn't extract a field that already exists on the item", function () {
var item = createUnsavedDataObject('item', { itemType: 'book' });
item.setField('numPages', 10);
@ -198,6 +204,17 @@ describe("Zotero.Utilities.Internal", function () {
assert.equal(fields.size, 0);
});
it("should extract an author and add it to existing creators", function () {
var item = createUnsavedDataObject('item', { itemType: 'book' });
item.setCreator(0, { creatorType: 'author', name: 'Foo' });
var str = 'author: Bar';
var { fields, creators, extra } = Zotero.Utilities.Internal.extractExtraFields(str, item);
assert.equal(fields.size, 0);
assert.lengthOf(creators, 1);
assert.equal(creators[0].creatorType, 'author');
assert.equal(creators[0].name, 'Bar');
});
it("should extract a CSL name", function () {
var str = 'container-author: First || Last';
var { creators, extra } = Zotero.Utilities.Internal.extractExtraFields(str);