update So 21. Jun 22:01:01 CEST 2020

This commit is contained in:
Robert Richter 2020-06-21 22:01:01 +02:00
parent 5b7a87a346
commit 001d2379de

View File

@ -10,8 +10,6 @@ module.exports = function (app_cfg, sql, waip, uuidv4, io, remote_api) {
function save_new_waip(waip_data, remote_addr, app_id) { function save_new_waip(waip_data, remote_addr, app_id) {
// ist JSON? // ist JSON?
if (isValidJSON(waip_data)) { if (isValidJSON(waip_data)) {
// Daten als JSON parsen
waip_data = JSON.parse(waip_data);
// Daten validieren // Daten validieren
validate_waip(waip_data, function (valid) { validate_waip(waip_data, function (valid) {
if (valid) { if (valid) {
@ -90,13 +88,20 @@ module.exports = function (app_cfg, sql, waip, uuidv4, io, remote_api) {
// Funktion um zu pruefen, ob Nachricht im JSON-Format ist // Funktion um zu pruefen, ob Nachricht im JSON-Format ist
function isValidJSON(json_obj) { function isValidJSON(json_obj) {
var text = JSON.stringify(json_obj); try {
if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { // versuche das JSON-Objekt zu parsen, falls es ein JSON-String ist
//the json is ok var tmp = JSON.parse(json_obj);
return true; return tmp;
} else { } catch (e) {
//the json is not ok // klappt das Parson nicht, versuche den JSON-String in String zu kopieren
return false; var text = JSON.stringify(json_obj);
// teste ob der String JSON-Konform ist
if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
var tmp = JSON.parse(json_obj);
return tmp;
} else {
return false;
};
}; };
}; };