Skip to content

Commit c90f76f

Browse files
authored
fix(Data Mapper): map not loading on some instances (Azure#3359)
fixed crashing on loading map on some instances
1 parent f5cfdca commit c90f76f

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

libs/data-mapper/src/lib/utils/DataMap.Utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export const splitKeyIntoChildren = (sourceKey: string): string[] => {
298298
} else {
299299
if (element === '"') {
300300
currentWord += element;
301-
if (functionParams[index + 1] && functionParams[index + 1] === ',') {
301+
if (openParenthesis === 0 && functionParams[index + 1] && functionParams[index + 1] === ',') {
302302
results.push(currentWord.trim());
303303
currentWord = '';
304304

libs/data-mapper/src/lib/utils/__test__/DataMapUtils.spec.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,33 @@ describe('utils/DataMap', () => {
213213
'string(EmployeeID)',
214214
]);
215215
});
216+
217+
it('Concat with three values including custom string', async () => {
218+
expect(splitKeyIntoChildren('concat(EmployeeName, "EmployeeAge", EmployeeID)')).toEqual([
219+
'EmployeeName',
220+
'"EmployeeAge"',
221+
'EmployeeID',
222+
]);
223+
});
224+
225+
it('Concat with three values surrounded by another function including custom string', async () => {
226+
expect(splitKeyIntoChildren('int(concat(/ns0:PersonOrigin/FirstName, " ",/ns0:PersonOrigin/LastName))')).toEqual([
227+
'concat(/ns0:PersonOrigin/FirstName, " ",/ns0:PersonOrigin/LastName)',
228+
]);
229+
});
230+
231+
it('Concat with three values surrounded by two other functions including custom string in the middle', async () => {
232+
expect(splitKeyIntoChildren('subtract(2023, int(concat(/ns0:PersonOrigin/FirstName, " ",/ns0:PersonOrigin/LastName)))')).toEqual([
233+
'2023',
234+
'int(concat(/ns0:PersonOrigin/FirstName, " ",/ns0:PersonOrigin/LastName))',
235+
]);
236+
});
237+
238+
it('Concat with three values surrounded by two other functions including custom string in the middle', async () => {
239+
expect(
240+
splitKeyIntoChildren('subtract(2023, int(concat("custom string", /ns0:PersonOrigin/FirstName, /ns0:PersonOrigin/LastName)))')
241+
).toEqual(['2023', 'int(concat("custom string", /ns0:PersonOrigin/FirstName, /ns0:PersonOrigin/LastName))']);
242+
});
216243
});
217244

218245
describe('qualifyLoopRelativeSourceKeys', () => {
@@ -332,6 +359,23 @@ describe('utils/DataMap', () => {
332359
'/ns0:TargetSchemaRoot/Looping/ManyToMany/$for(/ns0:SourceSchemaRoot/Looping/ManyToMany/Simple)/Simple/$for(SourceSimpleChild)/SimpleChild/$for(SourceSimpleChildChild)/SimpleChildChild/Direct'
333360
);
334361
});
362+
363+
it('returns unchanged string for multiple loops with custom string', () => {
364+
const result = removeSequenceFunction([
365+
'int',
366+
Separators.OpenParenthesis,
367+
'concat',
368+
Separators.OpenParenthesis,
369+
'"customString"',
370+
Separators.Comma,
371+
'/ns0:PersonOrigin/FirstName',
372+
Separators.Comma,
373+
'/ns0:PersonOrigin/LastName',
374+
Separators.CloseParenthesis,
375+
Separators.CloseParenthesis,
376+
]);
377+
expect(result).toEqual('int(concat("customString",/ns0:PersonOrigin/FirstName,/ns0:PersonOrigin/LastName))');
378+
});
335379
});
336380

337381
describe('separateIntoTokens', () => {
@@ -369,6 +413,49 @@ describe('utils/DataMap', () => {
369413
expect(result[13]).toEqual(Separators.CloseParenthesis);
370414
expect(result[14]).toEqual('/Person/Name');
371415
});
416+
417+
it('separates a loop and sequence target', () => {
418+
const result = separateIntoTokens('int(concat(/ns0:PersonOrigin/FirstName,/ns0:PersonOrigin/LastName))');
419+
expect(result[0]).toEqual('int');
420+
expect(result[1]).toEqual(Separators.OpenParenthesis);
421+
expect(result[2]).toEqual('concat');
422+
expect(result[3]).toEqual(Separators.OpenParenthesis);
423+
expect(result[4]).toEqual('/ns0:PersonOrigin/FirstName');
424+
expect(result[5]).toEqual(Separators.Comma);
425+
expect(result[6]).toEqual('/ns0:PersonOrigin/LastName');
426+
expect(result[7]).toEqual(Separators.CloseParenthesis);
427+
expect(result[8]).toEqual(Separators.CloseParenthesis);
428+
});
429+
430+
it('separates a loop and sequence target', () => {
431+
const result = separateIntoTokens('int(concat(/ns0:PersonOrigin/FirstName,/ns0:PersonOrigin/LastName,"customString"))');
432+
expect(result[0]).toEqual('int');
433+
expect(result[1]).toEqual(Separators.OpenParenthesis);
434+
expect(result[2]).toEqual('concat');
435+
expect(result[3]).toEqual(Separators.OpenParenthesis);
436+
expect(result[4]).toEqual('/ns0:PersonOrigin/FirstName');
437+
expect(result[5]).toEqual(Separators.Comma);
438+
expect(result[6]).toEqual('/ns0:PersonOrigin/LastName');
439+
expect(result[7]).toEqual(Separators.Comma);
440+
expect(result[8]).toEqual('"customString"');
441+
expect(result[9]).toEqual(Separators.CloseParenthesis);
442+
expect(result[10]).toEqual(Separators.CloseParenthesis);
443+
});
444+
445+
it('separates a loop and sequence target', () => {
446+
const result = separateIntoTokens('int(concat("customString",/ns0:PersonOrigin/FirstName,/ns0:PersonOrigin/LastName))');
447+
expect(result[0]).toEqual('int');
448+
expect(result[1]).toEqual(Separators.OpenParenthesis);
449+
expect(result[2]).toEqual('concat');
450+
expect(result[3]).toEqual(Separators.OpenParenthesis);
451+
expect(result[4]).toEqual('"customString"');
452+
expect(result[5]).toEqual(Separators.Comma);
453+
expect(result[6]).toEqual('/ns0:PersonOrigin/FirstName');
454+
expect(result[7]).toEqual(Separators.Comma);
455+
expect(result[8]).toEqual('/ns0:PersonOrigin/LastName');
456+
expect(result[9]).toEqual(Separators.CloseParenthesis);
457+
expect(result[10]).toEqual(Separators.CloseParenthesis);
458+
});
372459
});
373460
});
374461

0 commit comments

Comments
 (0)