mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-01-11 17:58:41 +00:00
Handle invalid json strings
This commit is contained in:
parent
a7d6bf4ec8
commit
4e400bf372
|
|
@ -64,6 +64,13 @@
|
||||||
*/
|
*/
|
||||||
jsOMS.UI.ActionManager.prototype.bindElement = function (e)
|
jsOMS.UI.ActionManager.prototype.bindElement = function (e)
|
||||||
{
|
{
|
||||||
|
if (!jsOMS.isValidJson(e.getAttribute('data-action'))) {
|
||||||
|
jsOMS.Log.Logger.instance.error('Invalid json string: \'' + e.getAttribute('data-action') + '\'');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: validate json, if invalid log error
|
||||||
const listeners = JSON.parse(e.getAttribute('data-action')),
|
const listeners = JSON.parse(e.getAttribute('data-action')),
|
||||||
listenerLength = listeners.length,
|
listenerLength = listeners.length,
|
||||||
self = this;
|
self = this;
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,25 @@
|
||||||
return str.replace(new RegExp("^[" + char + "]*"), '');
|
return str.replace(new RegExp("^[" + char + "]*"), '');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate json string
|
||||||
|
*
|
||||||
|
* @param {string} jsonString String to validate
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
jsOMS.isValidJson = function (jsonString)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
JSON.parse(jsonString);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count string in string
|
* Count string in string
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -390,6 +390,25 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate json string
|
||||||
|
*
|
||||||
|
* @param {string} jsonString String to validate
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
jsOMS.isValidJson = function (jsonString)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
JSON.parse(jsonString);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merging two arrays recursively
|
* Merging two arrays recursively
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user