Fix new attachment charset saving, which I definitely didn't test before
This commit is contained in:
parent
33eaaffd83
commit
7879e5432a
|
@ -106,7 +106,6 @@ Zotero.CachedTypes = function() {
|
||||||
|
|
||||||
if (!this._types['_' + idOrName]) {
|
if (!this._types['_' + idOrName]) {
|
||||||
Zotero.debug('Invalid ' + this._typeDesc + ' ' + idOrName, 1);
|
Zotero.debug('Invalid ' + this._typeDesc + ' ' + idOrName, 1);
|
||||||
Zotero.debug((new Error()).stack, 1);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,14 +509,14 @@ Zotero.CharacterSets = new function() {
|
||||||
name = name.toLowerCase();
|
name = name.toLowerCase();
|
||||||
|
|
||||||
// Don't allow too-long or non-ASCII names
|
// Don't allow too-long or non-ASCII names
|
||||||
if (name.length > 50 || !name.match(/[^a-z0-9\-_]/)) {
|
if (name.length > 50 || !name.match(/^[a-z0-9\-_]+$/)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sql = "INSERT INTO " + this._table + " (" + this._nameCol + ") VALUES (?)";
|
var sql = "INSERT INTO " + this._table + " (" + this._nameCol + ") VALUES (?)";
|
||||||
yield Zotero.DB.queryAsync(sql, name);
|
yield Zotero.DB.queryAsync(sql, name);
|
||||||
|
|
||||||
sql = "SELECT id FROM " + this._table + " WHERE " + this._nameCol + "=?";
|
sql = "SELECT " + this._idCol + " FROM " + this._table + " WHERE " + this._nameCol + "=?";
|
||||||
var id = yield Zotero.DB.valueQueryAsync(sql, name);
|
var id = yield Zotero.DB.valueQueryAsync(sql, name);
|
||||||
|
|
||||||
this._cacheTypeData({
|
this._cacheTypeData({
|
||||||
|
|
|
@ -201,6 +201,31 @@ describe("Zotero.Item", function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#attachmentCharset", function () {
|
||||||
|
it("should get and set a value", function* () {
|
||||||
|
var charset = 'utf-8';
|
||||||
|
var item = new Zotero.Item("attachment");
|
||||||
|
item.attachmentLinkMode = Zotero.Attachments.LINK_MODE_IMPORTED_FILE;
|
||||||
|
item.attachmentCharset = charset;
|
||||||
|
var itemID = yield item.save();
|
||||||
|
item = yield Zotero.Items.getAsync(itemID);
|
||||||
|
assert.equal(item.attachmentCharset, charset);
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not be marked as changed if not changed", function* () {
|
||||||
|
var charset = 'utf-8';
|
||||||
|
var item = new Zotero.Item("attachment");
|
||||||
|
item.attachmentLinkMode = Zotero.Attachments.LINK_MODE_IMPORTED_FILE;
|
||||||
|
item.attachmentCharset = charset;
|
||||||
|
var itemID = yield item.save();
|
||||||
|
item = yield Zotero.Items.getAsync(itemID);
|
||||||
|
|
||||||
|
// Set charset to same value
|
||||||
|
item.attachmentCharset = charset
|
||||||
|
assert.isFalse(item.hasChanged());
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("#attachmentFilename", function () {
|
describe("#attachmentFilename", function () {
|
||||||
it("should get and set a filename for a stored file", function* () {
|
it("should get and set a filename for a stored file", function* () {
|
||||||
var filename = "test.txt";
|
var filename = "test.txt";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user