Skip to content

Commit

Permalink
Fixing code using lookbehind + lookahead, for Safari (#314)
Browse files Browse the repository at this point in the history
* Replacing lookbehind + lookahead with safari-compatible code

* Adding a simple unit test

Co-authored-by: Ole Martin Handeland <[email protected]>
  • Loading branch information
olemartinorg and Ole Martin Handeland authored Jul 4, 2022
1 parent 786b839 commit 9f10ce5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/altinn-app-frontend/src/utils/databindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getKeyWithoutIndex,
mapFormData,
removeGroupData,
getKeyIndex,
} from './databindings';

describe('utils/databindings.ts', () => {
Expand Down Expand Up @@ -111,6 +112,12 @@ describe('utils/databindings.ts', () => {
];
});

describe('getKeyIndex', () => {
it('should work', () => {
expect(getKeyIndex('Group[1].Group2[0].group2prop')).toEqual([1, 0]);
});
});

describe('flattenObject', () => {
it('should return property of type number as a string', () => {
testObj.aNumber = 43;
Expand Down
4 changes: 2 additions & 2 deletions src/altinn-app-frontend/src/utils/databindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export function getKeyWithoutIndex(keyWithIndex: string): string {
* as an array => [0, 1]
*/
export function getKeyIndex(keyWithIndex: string): number[] {
const match = keyWithIndex.match(/(?<=\[)\d+(?=])]/g) || [];
return match.map((n) => parseInt(n, 10));
const match = keyWithIndex.match(/\[\d+]/g) || [];
return match.map((n) => parseInt(n.replace('[', '').replace(']', ''), 10));
}

/**
Expand Down

0 comments on commit 9f10ce5

Please sign in to comment.