diff --git a/src/morphlex.ts b/src/morphlex.ts index 4b55a30..07452d0 100644 --- a/src/morphlex.ts +++ b/src/morphlex.ts @@ -385,6 +385,7 @@ class Morph { // First pass: update/add attributes from reference (iterate forwards) for (const { name, value } of to.attributes) { + if (name === "morphlex-dirty") continue if (name === "value") { if (isInputElement(from) && from.type !== "file" && from.value !== value) { if (!this.#options.preserveChanges) { diff --git a/test/new/dirty-attribute-injection.browser.test.ts b/test/new/dirty-attribute-injection.browser.test.ts new file mode 100644 index 0000000..9b3e634 --- /dev/null +++ b/test/new/dirty-attribute-injection.browser.test.ts @@ -0,0 +1,16 @@ +import { expect, test } from "vitest" +import { morph } from "../../src/morphlex" + +test("morphlex-dirty attribute in `to` does not leak into `from`", () => { + const from = document.createElement("div") + from.id = "x" + + // Hostile/buggy input includes morphlex-dirty on the target. + const to = document.createElement("div") + to.id = "x" + to.setAttribute("morphlex-dirty", "") + + morph(from, to) + + expect(from.hasAttribute("morphlex-dirty")).toBe(false) +})