Skip to content

Commit f95d2f1

Browse files
committed
pat inject: Rebase URLs in pattern configuration attributes /3
Do not rebase pattern configuration values when they are empty. Solves a problem where accidently empty options (e.g. pat-inject url) are rebased and a subsequent pat-inject gets the rebased option inherited which then invalidly masks the href attribute of the subsequent pat-inject.
1 parent 4b398c7 commit f95d2f1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/pat/inject/inject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ const inject = {
931931
let changed = false;
932932
for (const opt of opts) {
933933
const val = options[opt];
934-
if (typeof val === "undefined") {
934+
if (!val) {
935935
continue;
936936
}
937937
changed = true;

src/pat/inject/inject.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,29 @@ describe("pat-inject", function () {
347347

348348
done();
349349
});
350+
351+
it("doesn't rebase invalid pattern configuration options", async (done) => {
352+
await import("../calendar/calendar");
353+
354+
const res = pattern._rebaseHTML(
355+
"https://example.com/test/",
356+
'<div id="test" data-pat-calendar="url: ; event-sources: ../calendar2.json"/>'
357+
);
358+
console.log(res);
359+
360+
const el = document.createElement("div");
361+
el.innerHTML = res;
362+
363+
const test_config = JSON.parse(
364+
el.querySelector("#test").getAttribute("data-pat-calendar")
365+
);
366+
expect(test_config.url).toEqual("");
367+
expect(test_config["event-sources"]).toEqual([
368+
"https://example.com/test/../calendar2.json",
369+
]);
370+
371+
done();
372+
});
350373
});
351374

352375
describe("parseRawHtml", function () {

0 commit comments

Comments
 (0)