Skip to content
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

[port] fix index access bug #1919

Merged
merged 1 commit into from
Mar 18, 2020
Merged
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
12 changes: 2 additions & 10 deletions libraries/adaptive-expressions/src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,9 @@ export class Extensions {
let value: any;
let error: string;

let count = -1;
if (Array.isArray(instance)) {
count = instance.length;
} else if (instance instanceof Map) {
count = (instance as Map<string, any>).size;
}
const indexer: string[] = Object.keys(instance);
if (count !== -1 && indexer.length > 0) {
if (index >= 0 && count > index) {
const idyn: any = instance;
value = idyn[index];
if (index >= 0 && index < instance.length) {
value = instance[index];
} else {
error = `${ index } is out of range for ${ instance }`;
}
Expand Down
11 changes: 11 additions & 0 deletions libraries/adaptive-expressions/tests/expressionParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const one = ['one'];
const oneTwo = ['one', 'two'];
const dataSource = [

// accessProperty and accessIndex
['alist[0].Name', 'item1'],

// string interpolation test
['`hi`', 'hi'],
['`hi\\``', 'hi`'],
Expand Down Expand Up @@ -572,6 +575,14 @@ const dataSource = [
];

const scope = {
alist: [
{
Name: 'item1'
},
{
Name: 'item2'
}
],
emptyList:[],
emptyObject: new Map(),
emptyJObject: {},
Expand Down