LTS - hotfix : Updates - Refined keyword matching to ensure keywords are not part of a string or a comment and are exact matches. (#1612)

* Updated validation logic to allow 'reservedKeyword.x' while treating standalone 'window' | 'app' | 'this' as a reserved keyword.

* bumped LTS version to 2.50.5.6

* fixes: evaluatin js code in codehinters with reserveed keyword

* fixes: reserved keywords string should be resolved and updated in the compnent

* add support to resolve methods from reserved keyword obj

* Fix: Update keyword validation to handle reserved keywords accurately

- Refined validation logic to handle reserved keywords, ensuring that compound identifiers are not incorrectly flagged.
- Improved checks to allow valid code patterns like 'window.location.href' while blocking invalid usage of 'window'.
- Addressed all known cases, including those causing app or component crashes and previously non-working cases.
- Enhanced handling for both multiline and single line code validation.

* remove console
This commit is contained in:
Arpit 2024-06-25 16:18:36 +05:30 committed by Kavin Venkatachalam
parent a90dac5f8b
commit 68d9f172e3
2 changed files with 12 additions and 11 deletions

View file

@ -4,7 +4,7 @@ import _, { isEmpty } from 'lodash';
import { useCurrentStateStore } from '@/_stores/currentStateStore';
import { any } from 'superstruct';
import { generateSchemaFromValidationDefinition, validate } from '../component-properties-validation';
import { hasCircularDependency } from '@/_helpers/utils';
import { hasCircularDependency, resolveReferences as olderResolverMethod } from '@/_helpers/utils';
import { validateMultilineCode } from '@/_helpers/utility';
const acorn = require('acorn');

View file

@ -164,7 +164,6 @@ export function resolveReferences(
if (object === '{{{}}}') return '';
object = _.clone(object);
const currentState = useCurrentStateStore.getState();
const objectType = typeof object;
let error;
@ -173,29 +172,31 @@ export function resolveReferences(
switch (objectType) {
case 'string': {
if (object.includes('{{') && object.includes('}}') && object.includes('%%') && object.includes('%%')) {
object = resolveString(object, currentState, customObjects, reservedKeyword, withError, forPreviewBox);
object = resolveString(object, state, customObjects, reservedKeyword, withError, forPreviewBox);
}
if (object.startsWith('{{') && object.endsWith('}}')) {
if ((object.match(/{{/g) || []).length === 1) {
const code = object.replace('{{', '').replace('}}', '');
const _reservedKeyword = ['app', 'window', 'this']; // Case-sensitive reserved keywords
const keywordRegex = new RegExp(`\\b(${_reservedKeyword.join('|')})\\b`, 'i');
//Will be remove in next release
if (code.match(keywordRegex)) {
error = `${code} is a reserved keyword`;
return [{}, error];
const { status, data } = validateMultilineCode(code);
if (status === 'failed') {
const errMessage = `${data.message} - ${data.description}`;
return [{}, errMessage];
}
return resolveCode(code, currentState, customObjects, withError, reservedKeyword, true);
return resolveCode(code, state, customObjects, withError, [], true);
} else {
const dynamicVariables = getDynamicVariables(object);
for (const dynamicVariable of dynamicVariables) {
const value = resolveString(
dynamicVariable,
currentState,
state,
customObjects,
reservedKeyword,
withError,
@ -215,7 +216,7 @@ export function resolveReferences(
return [{}, error];
}
return resolveCode(code, currentState, customObjects, withError, reservedKeyword, false);
return resolveCode(code, state, customObjects, withError, reservedKeyword, false);
}
const dynamicVariables = getDynamicVariables(object);