* detect json better

This commit is contained in:
Ingo Fischer
2023-01-03 00:38:58 +01:00
parent 8fc6f4ac01
commit 62ef7cabf8
+5 -2
View File
@@ -40,7 +40,9 @@ function startAdapter(options) {
const target = {}; const target = {};
let requestFields = {}; let requestFields = {};
if (typeof state.val === 'string' && state.val.startsWith('{') && state.val.endsWith('}')) { if (typeof state.val === 'string') {
state.val = state.val.trim();
if (state.val.startsWith('{') && state.val.endsWith('}')) {
try { try {
requestFields = JSON.parse(state.val) || {}; requestFields = JSON.parse(state.val) || {};
} catch (err) { } catch (err) {
@@ -48,8 +50,9 @@ function startAdapter(options) {
requestFields = {}; requestFields = {};
} }
} }
}
// If a non-JSON value was set and we only have one relevant field, use this field as value // If a non-JSON value was set, and we only have one relevant field, use this field as value
if (fields && Object.keys(requestFields).length === 0) { if (fields && Object.keys(requestFields).length === 0) {
const fieldList = Object.keys(fields); const fieldList = Object.keys(fields);
if (fieldList.length === 1 && fieldList[0] !== 'entity_id') { if (fieldList.length === 1 && fieldList[0] !== 'entity_id') {