Skip to content

remove autocast feature #1323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AlvaroVega opened this issue Mar 22, 2023 · 3 comments
Closed

remove autocast feature #1323

AlvaroVega opened this issue Mar 22, 2023 · 3 comments

Comments

@AlvaroVega
Copy link
Member

Autocast feature is currently doing unexpected and unwanted transformations which could be done by jexl in a controlled way, so it must be fully removed.

Maybe related with #1037

function castJsonNativeAttributes(payload) {
if (!config.getConfig().autocast) {
return payload;
}
for (const key in payload) {
if (
/* eslint-disable-next-line no-prototype-builtins */
payload.hasOwnProperty(key) &&
payload[key].value &&
payload[key].type &&
typeof payload[key].value === 'string'
) {
if (payload[key].type === 'Number' && isFloat(payload[key].value)) {
payload[key].value = Number.parseFloat(payload[key].value);
} else if (payload[key].type === 'Number' && Number.parseInt(payload[key].value)) {
payload[key].value = Number.parseInt(payload[key].value);
} else if (payload[key].type === 'Boolean') {
payload[key].value = payload[key].value === 'true' || payload[key].value === '1';
} else if (payload[key].type === 'None') {
payload[key].value = null;
} else if (payload[key].type === 'Array' || payload[key].type === 'Object') {
try {
const parsedValue = JSON.parse(payload[key].value);
payload[key].value = parsedValue;
} catch (e) {
logger.error(
context,
'Bad attribute value type. Expecting JSON Array or JSON Object. Received:%s',
payload[key].value
);
}
}
}
}
return payload;
}

@AlvaroVega
Copy link
Member Author

AlvaroVega commented Mar 22, 2023

Alternativally autocast could be reimplemented with just:

try {
  value = JSON.parse(value);
} catch (e) {
   // keep value as 
}

@mrutid
Copy link
Member

mrutid commented Mar 22, 2023

We are losing the autocast for the case:
1->true
Which still avaliable via JEXL explicit casting.

@fgalan
Copy link
Member

fgalan commented Mar 27, 2023

Fixed by PR #1324

@fgalan fgalan closed this as completed Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants