mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
466cb4be89
commit
cdb173fd6e
@ -276,10 +276,21 @@ RED.clipboard = (function() {
|
|||||||
if (typeof value !== "string" ) {
|
if (typeof value !== "string" ) {
|
||||||
value = JSON.stringify(value, function(key,value) {
|
value = JSON.stringify(value, function(key,value) {
|
||||||
if (value !== null && typeof value === 'object') {
|
if (value !== null && typeof value === 'object') {
|
||||||
if (value.__encoded__ && value.hasOwnProperty('data') && value.hasOwnProperty('length')) {
|
if (value.__encoded__) {
|
||||||
|
if (value.hasOwnProperty('data') && value.hasOwnProperty('length')) {
|
||||||
truncated = value.data.length !== value.length;
|
truncated = value.data.length !== value.length;
|
||||||
return value.data;
|
return value.data;
|
||||||
}
|
}
|
||||||
|
if (value.type === 'function' || value.type === 'internal') {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
if (value.type === 'number') {
|
||||||
|
// Handle NaN and Infinity - they are not permitted
|
||||||
|
// in JSON. We can either substitute with a String
|
||||||
|
// representation or null
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
});
|
});
|
||||||
|
@ -36,6 +36,8 @@ RED.utils = (function() {
|
|||||||
result = $('<span class="debug-message-object-value debug-message-type-meta"></span>').text('array['+value.length+']');
|
result = $('<span class="debug-message-object-value debug-message-type-meta"></span>').text('array['+value.length+']');
|
||||||
} else if (value.hasOwnProperty('type') && value.type === 'function') {
|
} else if (value.hasOwnProperty('type') && value.type === 'function') {
|
||||||
result = $('<span class="debug-message-object-value debug-message-type-meta"></span>').text('function');
|
result = $('<span class="debug-message-object-value debug-message-type-meta"></span>').text('function');
|
||||||
|
} else if (value.hasOwnProperty('type') && value.type === 'number') {
|
||||||
|
result = $('<span class="debug-message-object-value debug-message-type-number"></span>').text(value.data);
|
||||||
} else {
|
} else {
|
||||||
result = $('<span class="debug-message-object-value debug-message-type-meta">object</span>');
|
result = $('<span class="debug-message-object-value debug-message-type-meta">object</span>');
|
||||||
}
|
}
|
||||||
@ -47,6 +49,8 @@ RED.utils = (function() {
|
|||||||
subvalue = sanitize(value);
|
subvalue = sanitize(value);
|
||||||
}
|
}
|
||||||
result = $('<span class="debug-message-object-value debug-message-type-string"></span>').html('"'+formatString(subvalue)+'"');
|
result = $('<span class="debug-message-object-value debug-message-type-string"></span>').html('"'+formatString(subvalue)+'"');
|
||||||
|
} else if (typeof value === 'number') {
|
||||||
|
result = $('<span class="debug-message-object-value debug-message-type-number"></span>').text(""+value);
|
||||||
} else {
|
} else {
|
||||||
result = $('<span class="debug-message-object-value debug-message-type-other"></span>').text(""+value);
|
result = $('<span class="debug-message-object-value debug-message-type-other"></span>').text(""+value);
|
||||||
}
|
}
|
||||||
@ -300,6 +304,8 @@ RED.utils = (function() {
|
|||||||
}
|
}
|
||||||
if (obj === null || obj === undefined) {
|
if (obj === null || obj === undefined) {
|
||||||
$('<span class="debug-message-type-null">'+obj+'</span>').appendTo(entryObj);
|
$('<span class="debug-message-type-null">'+obj+'</span>').appendTo(entryObj);
|
||||||
|
} else if (obj.__encoded__ && obj.type === 'number') {
|
||||||
|
e = $('<span class="debug-message-type-number debug-message-object-header"></span>').text(obj.data).appendTo(entryObj);
|
||||||
} else if (typeHint === "function" || (obj.__encoded__ && obj.type === 'function')) {
|
} else if (typeHint === "function" || (obj.__encoded__ && obj.type === 'function')) {
|
||||||
e = $('<span class="debug-message-type-meta debug-message-object-header"></span>').text("function").appendTo(entryObj);
|
e = $('<span class="debug-message-type-meta debug-message-object-header"></span>').text("function").appendTo(entryObj);
|
||||||
} else if (typeHint === "internal" || (obj.__encoded__ && obj.type === 'internal')) {
|
} else if (typeHint === "internal" || (obj.__encoded__ && obj.type === 'internal')) {
|
||||||
@ -799,6 +805,10 @@ RED.utils = (function() {
|
|||||||
function decodeObject(payload,format) {
|
function decodeObject(payload,format) {
|
||||||
if ((format === 'number') && (payload === "NaN")) {
|
if ((format === 'number') && (payload === "NaN")) {
|
||||||
payload = Number.NaN;
|
payload = Number.NaN;
|
||||||
|
} else if ((format === 'number') && (payload === "Infinity")) {
|
||||||
|
payload = Infinity;
|
||||||
|
} else if ((format === 'number') && (payload === "-Infinity")) {
|
||||||
|
payload = -Infinity;
|
||||||
} else if (format === 'Object' || /^array/.test(format) || format === 'boolean' || format === 'number' ) {
|
} else if (format === 'Object' || /^array/.test(format) || format === 'boolean' || format === 'number' ) {
|
||||||
payload = JSON.parse(payload);
|
payload = JSON.parse(payload);
|
||||||
} else if (/error/i.test(format)) {
|
} else if (/error/i.test(format)) {
|
||||||
|
@ -469,6 +469,14 @@ function encodeObject(msg,opts) {
|
|||||||
__encoded__: true,
|
__encoded__: true,
|
||||||
type: "function"
|
type: "function"
|
||||||
}
|
}
|
||||||
|
} else if (typeof value === 'number') {
|
||||||
|
if (isNaN(value) || value === Infinity || value === -Infinity) {
|
||||||
|
value = {
|
||||||
|
__encoded__: true,
|
||||||
|
type: "number",
|
||||||
|
data: value.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (value && value.constructor) {
|
} else if (value && value.constructor) {
|
||||||
if (value.type === "Buffer") {
|
if (value.type === "Buffer") {
|
||||||
value.__encoded__ = true;
|
value.__encoded__ = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user