Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pages): script tags can now be executed if they are provided through advanced settings #4824

Merged
merged 4 commits into from
Mar 11, 2025
Merged
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
26 changes: 25 additions & 1 deletion apps/pages/src/components/ViewPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<router-link v-if="canEdit" :to="'/' + page + '/edit'">
edit page
</router-link>
<div v-html="contents"></div>
<div ref="pageContents"></div>
</div>
</template>

Expand Down Expand Up @@ -32,5 +32,29 @@ export default {
);
},
},
watch: {
contents(htmlString) {
const parser = new DOMParser();
const doc = parser.parseFromString(htmlString, "text/html");

/** Loop over the just parsed html items, and add them */
Array.from(doc.body.children).forEach((el) => {
if (el.tagName !== "SCRIPT") {
this.$refs.pageContents.appendChild(el);
} else {
/** Script tags need a special treatment, else they will not execute. **/
const scriptEl = document.createElement("script");
if (el.src) {
/** If we have an external script. */
scriptEl.src = el.src;
} else {
/** Regular inline script */
scriptEl.textContent = el.textContent;
}
this.$refs.pageContents.appendChild(scriptEl);
}
});
},
},
};
</script>
Loading