closes #1706, [PATCH] Item with non-ASCII characters corrupted on save when Show Editor is open

The problem here was that entities weren't properly being encoded as Unicode RTF when the editor was used, because TinyMCE was replacing high characters with HTML entities that were not properly decoded. This is now fixed.
This commit is contained in:
Simon Kornblith 2010-08-01 19:53:08 +00:00
parent cb1446fdea
commit c9003f1f40

View file

@ -76,7 +76,6 @@
this._htmlToRtfMap = [ this._htmlToRtfMap = [
[/"(\w)/, "“$1"], [/"(\w)/, "“$1"],
[/([\w,.?!])"/, "$1”"], [/([\w,.?!])"/, "$1”"],
[/[\x7F-\uFFFF]/g, function(aChar) { return "\\uc0\\u"+aChar.charCodeAt(0).toString()+" " }],
["<p>", ""], ["<p>", ""],
["</p>", "\\par "], ["</p>", "\\par "],
[/<\/?div[^>]*>/g, ""], [/<\/?div[^>]*>/g, ""],
@ -179,6 +178,7 @@
<!-- Sets or returns contents of rich text box --> <!-- Sets or returns contents of rich text box -->
<property name="value"> <property name="value">
<getter><![CDATA[ <getter><![CDATA[
const highcharRe = /[\x7F-\uFFFF]/g;
var output = this._editor.getContent(); var output = this._editor.getContent();
if(this._format == "RTF") { if(this._format == "RTF") {
@ -213,9 +213,12 @@
for each(var entry in this._htmlToRtfMap) { for each(var entry in this._htmlToRtfMap) {
output = output.replace(entry[0], entry[1], "g"); output = output.replace(entry[0], entry[1], "g");
} }
output = Zotero.Utilities.prototype.trim(output); output = Zotero.Utilities.prototype.trim(output)
output = output.replace(" ", "&nbsp;", "g"); output = Zotero.Utilities.prototype.unescapeHTML(
output = Zotero.Utilities.prototype.unescapeHTML(output); output.replace(" ", "&nbsp;", "g"))
.replace(highcharRe,
function(aChar) { return "\\uc0\\u"+aChar.charCodeAt(0).toString()+" " });
if(output.substr(-4) == "\\par") output = output.substr(0, output.length-4); if(output.substr(-4) == "\\par") output = output.substr(0, output.length-4);
} }