Skip to content

Commit ff403bb

Browse files
committed
prevent crash when passing * to ignore_attributes (#3997)
Closes #3996.
1 parent 67a3bc0 commit ff403bb

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

assets/js/phoenix_live_view/js.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ const JS = {
334334
attrs.some(
335335
(toIgnore) =>
336336
attr.name == toIgnore ||
337+
toIgnore === "*" ||
337338
(toIgnore.includes("*") && attr.name.match(toIgnore) != null),
338339
)
339340
) {

assets/test/view_test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,47 @@ describe("View + DOM", function () {
10031003
expect(view.el.firstChild.getAttribute("data-new")).toBe("new");
10041004
expect(view.el.firstChild.textContent.replace(/\s+/g, "")).toEqual("A1");
10051005
});
1006+
1007+
test("ignore_attributes *", () => {
1008+
let liveSocket = new LiveSocket("/live", Socket);
1009+
let el = liveViewDOM();
1010+
let updateDiff = {
1011+
"0": ' phx-mounted="[["ignore_attrs",{"attrs":["open","*"]}]]"',
1012+
"1": ' data-foo="foo" data-bar="bar"',
1013+
"2": "0",
1014+
s: [
1015+
"<details",
1016+
"",
1017+
">\n <summary>A</summary>\n <span>",
1018+
"</span></details>",
1019+
],
1020+
};
1021+
1022+
let view = simulateJoinedView(el, liveSocket);
1023+
view.applyDiff("update", updateDiff, ({ diff, events }) =>
1024+
view.update(diff, events),
1025+
);
1026+
1027+
expect(view.el.firstChild.tagName).toBe("DETAILS");
1028+
expect(view.el.firstChild.open).toBe(false);
1029+
view.el.firstChild.open = true;
1030+
view.el.firstChild.setAttribute("data-foo", "bar");
1031+
view.el.firstChild.setAttribute("data-other", "also kept");
1032+
view.el.firstChild.setAttribute("something", "else");
1033+
// apply diff
1034+
view.applyDiff(
1035+
"update",
1036+
{ "1": 'data-foo="foo" data-bar="bar" data-new="new"', "2": "1" },
1037+
({ diff, events }) => view.update(diff, events),
1038+
);
1039+
expect(view.el.firstChild.open).toBe(true);
1040+
expect(view.el.firstChild.getAttribute("data-foo")).toBe("bar");
1041+
expect(view.el.firstChild.getAttribute("data-bar")).toBe("bar");
1042+
expect(view.el.firstChild.getAttribute("something")).toBe("else");
1043+
expect(view.el.firstChild.getAttribute("data-other")).toBe("also kept");
1044+
expect(view.el.firstChild.getAttribute("data-new")).toBe("new");
1045+
expect(view.el.firstChild.textContent.replace(/\s+/g, "")).toEqual("A1");
1046+
});
10061047
});
10071048
});
10081049

0 commit comments

Comments
 (0)