Skip to content

Commit 7580a73

Browse files
committed
Add test for normalizeModelName and explain change within
1 parent a194f0c commit 7580a73

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/LiveComponent/assets/src/set_deep_data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ export function doesDeepPropertyExist(data, propertyPath) {
7575
*/
7676
export function normalizeModelName(model) {
7777
return model
78+
// Names ending in "[]" represent arrays in HTML.
79+
// To get normalized name we need to ignore this part.
80+
// For example: "user[mailing][]" becomes "user.mailing" (and has array typed value)
7881
.replace(/\[]$/, '')
7982
.split('[')
8083
// ['object', 'foo', 'bar', 'ya']

src/LiveComponent/assets/test/set_deep_data.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,8 @@ describe('normalizeModelName', () => {
9696
it('can normalize a string with []', () => {
9797
expect(normalizeModelName('user[firstName]')).toEqual('user.firstName');
9898
});
99+
100+
it('can normalize a string ending in []', () => {
101+
expect(normalizeModelName('user[mailing][]')).toEqual('user.mailing');
102+
});
99103
});

0 commit comments

Comments
 (0)