commit b073c3e68092edeab61a6afad9819b0f1b4e0ae2
parent 10111dbd98c140620b9fb97d40895f0d0e74149a
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 30 Jan 2017 13:33:23 -0500
Fix mangled output from Zotero.Utilities.getAsyncInputStream()
Proper fix (as opposed to 5236d01791f) for
https://forums.zotero.org/discussion/64022/5-0-beta-generate-report-is-often-garbled
Diffstat:
2 files changed, 11 insertions(+), 25 deletions(-)
diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js
@@ -658,16 +658,18 @@ Zotero.Utilities.Internal = {
var g = gen.next ? gen : gen();
var seq = 0;
+ const PR_UINT32_MAX = Math.pow(2, 32) - 1;
var pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
- pipe.init(true, true, 0, 0, null);
+ pipe.init(true, true, 0, PR_UINT32_MAX, null);
var os = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
.createInstance(Components.interfaces.nsIConverterOutputStream);
os.init(pipe.outputStream, 'utf-8', 0, 0x0000);
+
pipe.outputStream.asyncWait({
onOutputStreamReady: function (aos) {
- Zotero.debug("Output stream is ready");
+ //Zotero.debug("Output stream is ready");
let currentSeq = seq++;
@@ -710,6 +712,12 @@ Zotero.Utilities.Internal = {
}
}
+ if (error) {
+ Zotero.debug("Closing input stream");
+ aos.close();
+ throw error;
+ }
+
if (typeof data != 'string') {
throw new Error("Yielded value is not a string or promise in " + funcName
+ " ('" + data + "')");
@@ -733,14 +741,6 @@ Zotero.Utilities.Internal = {
Zotero.debug("Writing " + data.length + " characters");
os.writeString(data);
- if (error) {
- Zotero.debug("Closing input stream");
- aos.close();
- throw error;
- }
-
- Zotero.debug("Waiting to write more");
-
// Wait until stream is ready for more
aos.asyncWait(this, 0, 0, null);
}, this)
diff --git a/components/zotero-protocol-handler.js b/components/zotero-protocol-handler.js
@@ -444,26 +444,12 @@ function ZoteroProtocolHandler() {
default:
this.contentType = 'text/html';
-
- // DEBUG: Results in mangled reports
- //
- // https://forums.zotero.org/discussion/64022/5-0-beta-generate-report-is-often-garbled
- /*return Zotero.Utilities.Internal.getAsyncInputStream(
- Zotero.Report.HTML.listGenerator(items, combineChildItems),
- function () {
- return '<span style="color: red; font-weight: bold">Error generating report</span>';
- }
- );*/
-
- Components.utils.import("resource://gre/modules/NetUtil.jsm");
- var is = Zotero.Utilities.Internal.getAsyncInputStream(
+ return Zotero.Utilities.Internal.getAsyncInputStream(
Zotero.Report.HTML.listGenerator(items, combineChildItems),
function () {
return '<span style="color: red; font-weight: bold">Error generating report</span>';
}
);
- var str = NetUtil.readInputStreamToString(is, is.available(), { charset: "UTF-8" });
- return Zotero.Promise.resolve(str);
}
});
}