Some more fixes related to unicode and escape chars
This commit is contained in:
parent
9cdff41afa
commit
0b234f6375
|
@ -984,7 +984,6 @@ Node.prototype._getDomValue = function(silent) {
|
|||
try {
|
||||
// retrieve the value
|
||||
var value;
|
||||
console.log('getValue', this.valueInnerText, this.valueInnerText.length)
|
||||
if (this.type == 'string') {
|
||||
value = this._unescapeHTML(this.valueInnerText);
|
||||
}
|
||||
|
@ -2858,13 +2857,16 @@ Node.prototype._stringCast = function(str) {
|
|||
* @private
|
||||
*/
|
||||
Node.prototype._escapeHTML = function (text) {
|
||||
return String(text)
|
||||
var htmlEscaped = String(text)
|
||||
.replace(/&/g, '&') // must be replaced first!
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/ /g, ' ') // replace double space with an nbsp and space
|
||||
.replace(/^ /, ' ') // space at start
|
||||
.replace(/ $/, ' '); // space at end
|
||||
|
||||
var json = JSON.stringify(htmlEscaped);
|
||||
return json.substring(1, json.length - 1);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -2874,7 +2876,10 @@ Node.prototype._escapeHTML = function (text) {
|
|||
* @private
|
||||
*/
|
||||
Node.prototype._unescapeHTML = function (escapedText) {
|
||||
return this._escapeJSON(escapedText)
|
||||
var json = '"' + this._escapeJSON(escapedText) + '"';
|
||||
var htmlEscaped = util.parse(json);
|
||||
|
||||
return htmlEscaped
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/ |\u00A0/g, ' ')
|
||||
|
|
|
@ -45,15 +45,17 @@
|
|||
modes: ['code', 'form', 'text', 'tree', 'view'], // allowed modes
|
||||
error: function (err) {
|
||||
alert(err.toString());
|
||||
}
|
||||
},
|
||||
indentation: 4
|
||||
};
|
||||
|
||||
json = {
|
||||
"array": [1, 2, 3],
|
||||
"boolean": true,
|
||||
"htmlcode": '"',
|
||||
"unicode": '\\u20b9',
|
||||
"invalid": '\u20b9',
|
||||
"escaped_unicode": '\\u20b9',
|
||||
"unicode": '\u20b9',
|
||||
"return": '\n',
|
||||
"null": null,
|
||||
"number": 123,
|
||||
"object": {"a": "b", "c": "d"},
|
||||
|
@ -61,6 +63,8 @@
|
|||
};
|
||||
|
||||
editor = new JSONEditor(container, options, json);
|
||||
|
||||
console.log(JSON.stringify(json));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue