Fix getContentsAsync() with invalid characters
This commit is contained in:
parent
424cae173b
commit
20ca8edf87
|
@ -210,9 +210,9 @@ Zotero.File = new function(){
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
charset: charset ? charset : "UTF-8",
|
charset: charset ? charset : "UTF-8",
|
||||||
// This doesn't seem to work -- reading an image file still throws NS_ERROR_ILLEGAL_INPUT
|
replacement: 65533
|
||||||
replacement: "\uFFFD"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var deferred = Zotero.Promise.defer();
|
var deferred = Zotero.Promise.defer();
|
||||||
NetUtil.asyncFetch(source, function(inputStream, status) {
|
NetUtil.asyncFetch(source, function(inputStream, status) {
|
||||||
if (!Components.isSuccessCode(status)) {
|
if (!Components.isSuccessCode(status)) {
|
||||||
|
|
1
test/tests/data/invalidChar.txt
Normal file
1
test/tests/data/invalidChar.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
A®B
|
1
test/tests/data/utf8Char.txt
Normal file
1
test/tests/data/utf8Char.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
A犬B
|
|
@ -4,6 +4,22 @@ describe("Zotero.File", function () {
|
||||||
var path = OS.Path.join(getTestDataDirectory().path, "empty");
|
var path = OS.Path.join(getTestDataDirectory().path, "empty");
|
||||||
assert.equal((yield Zotero.File.getContentsAsync(path)), "");
|
assert.equal((yield Zotero.File.getContentsAsync(path)), "");
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should handle an extended character", function* () {
|
||||||
|
var contents = yield Zotero.File.getContentsAsync(
|
||||||
|
OS.Path.join(getTestDataDirectory().path, "utf8Char.txt")
|
||||||
|
);
|
||||||
|
assert.lengthOf(contents, 3);
|
||||||
|
assert.equal(contents, "A\u72acB");
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should handle an invalid character", function* () {
|
||||||
|
var contents = yield Zotero.File.getContentsAsync(
|
||||||
|
OS.Path.join(getTestDataDirectory().path, "invalidChar.txt")
|
||||||
|
);
|
||||||
|
assert.lengthOf(contents, 3);
|
||||||
|
assert.equal(contents, "A\uFFFDB");
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("#copyDirectory()", function () {
|
describe("#copyDirectory()", function () {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user