Skip to content
Closed
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
1 change: 1 addition & 0 deletions src/LiveComponent/assets/dist/live_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ function trimAll(str) {
return str.replace(/[\s]+/g, " ").trim();
}
function normalizeModelName(model) {
if (!model.includes("[") && !model.includes("]")) return model;
return model.replace(/\[]$/, "").split("[").map((s) => s.replace("]", "")).join(".");
}
function getValueFromElement(element, valueStore) {
Expand Down
6 changes: 6 additions & 0 deletions src/LiveComponent/assets/src/string_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export function trimAll(str: string) {
* For example: "user[firstName]" becomes "user.firstName"
*/
export function normalizeModelName(model: string): string {
// Most model names are plain (e.g. "query"), and the pipeline below is a
// no-op for them. ValueStore also normalizes already-normalized names.
if (!model.includes('[') && !model.includes(']')) {
return model;
}

return (
model
// Names ending in "[]" represent arrays in HTML.
Expand Down
4 changes: 4 additions & 0 deletions src/LiveComponent/assets/test/unit/string_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ describe('normalizeModelName', () => {
it('can normalize a string ending in []', () => {
expect(normalizeModelName('user[mailing][]')).toEqual('user.mailing');
});

it('strips a stray closing bracket', () => {
expect(normalizeModelName('weird]name')).toEqual('weirdname');
});
});
Loading