Skip to content

fix: [#4860] Adaptive expression context access with non-standard objects #4876

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions libraries/adaptive-expressions/src/functionUtils.internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,8 @@ export class InternalFunctionUtils {
if (instance instanceof Map && (instance as Map<string, any>) !== undefined) {
const instanceMap: Map<string, any> = instance as Map<string, any>;
value = instanceMap.get(property);
if (value === undefined) {
const prop: string = Array.from(instanceMap.keys()).find(
(k: string): boolean => k.toLowerCase() === property.toLowerCase(),
);
if (prop !== undefined) {
value = instanceMap.get(prop);
}
}
} else {
const prop: string = Object.keys(instance).find(
(k: string): boolean => k.toLowerCase() === property.toLowerCase(),
);
if (prop !== undefined) {
value = instance[prop];
}
value = instance[property];
}

return { value, error };
Expand Down
28 changes: 14 additions & 14 deletions libraries/adaptive-expressions/tests/expressionParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const testCases = [
['"ab\\ycd"', 'ab\\ycd'], //"ab\ycd" -> ab\ycd
["'ab\\'cd'", "ab'cd"], // 'ab\'cd' -> ab'cd
['alist[0].Name', 'item1'],
['alist[0].name', undefined], // case sensitive, should not be found
],
},
{
Expand Down Expand Up @@ -170,16 +171,15 @@ const testCases = [
['bag.name == null ? "hello": bag.name', 'mybag'],
['one > 0? one : two', 1],
['hello * 5?"r1":"r2"', 'r2'],
['timestampObj < timestampObj2', false],
['timestampObj2 < timestampObj', true],
['timestampObj > timestampObj2', true],
['timestampObj2 > timestampObj', false],
['timestampObj >= timestampObj2', true],
['timestampObj2 >= timestampObj', false],
['timestampObj <= timestampObj2', false],
['timestampObj2 <= timestampObj', true],
['timestampObj == timestampObj2', false],
['timestampObj == timestampObj', true],
['timeStampObj2 < timeStampObj', true],
['timeStampObj > timeStampObj2', true],
['timeStampObj2 > timeStampObj', false],
['timeStampObj >= timeStampObj2', true],
['timeStampObj2 >= timeStampObj', false],
['timeStampObj <= timeStampObj2', false],
['timeStampObj2 <= timeStampObj', true],
['timeStampObj == timeStampObj2', false],
['timeStampObj == timeStampObj', true],
['where([{a: 1, b:{c: 2}}, {b: 2}], x, x == { b: { c: 2}, a: 1})[0].b.c', 2],
],
},
Expand Down Expand Up @@ -578,7 +578,7 @@ const testCases = [
["formatDateTime('2018-03-15T11:00:00.123', 't')", 'AM'],
["formatDateTime('2018-03-15T11:00:00.123', 'tt')", 'AM'],
["formatDateTime('2018-03-15')", '2018-03-15T00:00:00.000Z'],
['formatDateTime(timestampObj)', '2018-03-15T13:00:00.000Z'],
['formatDateTime(timeStampObj)', '2018-03-15T13:00:00.000Z'],
['formatEpoch(unixTimestamp)', '2018-03-15T13:00:00.000Z'],
["formatEpoch(unixTimestamp, 'MM-dd', 'es-ES')", '03-15'],
['formatEpoch(unixTimestampFraction)', '2018-03-15T13:00:00.500Z'],
Expand Down Expand Up @@ -792,8 +792,8 @@ const testCases = [
'string(merge(json1, json2, json3))',
'{"FirstName":"John","LastName":"Smith","Enabled":true,"Roles":["Customer","Admin"],"age":36}',
],
['merge(callstack[1], callstack[2]).z', 1],
['merge(callstack).z', 1],
['merge(callStack[1], callStack[2]).z', 1],
['merge(callStack).z', 1],
[
"string(merge({k1:'v1'}, [{k2:'v2'}, {k3: 'v3'}], {k4:'v4'}))",
'{"k1":"v1","k2":"v2","k3":"v3","k4":"v4"}',
Expand Down Expand Up @@ -987,7 +987,7 @@ const scope = {
validTimeRange: new TimexProperty({ partOfDay: 'morning' }),
validNow: new TimexProperty({ now: true }),
invalidHourTimex: new TimexProperty('2001-02-20'),
timestampObj: new Date('2018-03-15T13:00:00.000Z'),
timeStampObj: new Date('2018-03-15T13:00:00.000Z'),
timeStampObj2: new Date('2018-01-02T02:00:00.000Z'),
unixTimestamp: 1521118800,
unixTimestampFraction: 1521118800.5,
Expand Down
Loading