chantouchsek / v-sanitize

Whitelist-based HTML sanitizer for Vue.js apps.
MIT License
16 stars 5 forks source link

Support Vue 3 and Nuxt 3 #265

Open truesteps opened 2 years ago

truesteps commented 2 years ago

Heya! Are you planning a tag released for vue 3?

truesteps commented 2 years ago

@Chantouch i'm working on a vue 3 rewrite, just didn't get to write tests yet, gonna send a pull request asap.... Altho, it seems, sanitize-html doesn't work with Vite :(

chantouchsek commented 2 years ago

Lol, Thanks for working on it. Let see if sanitize-html can work with vite. 🍡

chantouchsek commented 2 years ago

Can you create a draft PR for it?

truesteps commented 2 years ago

284 added it, as well as sent a bug report for sanitize-html https://github.com/apostrophecms/sanitize-html/issues/553

danluchs commented 1 year ago

Any movement on this? We'd really like to use this package with our upcoming Nuxt 3 project.

It looks like the issue I'm seeing is on line 55 of src/sanitize.ts, at least for our installation. Nuxt is throwing this error, when trying to set $sanitize on the Vue.prototype:

Cannot set properties of undefined (setting '$sanitize')

This may fix the issue:

const vueProto = Vue?.config?.globalProperties ?? Vue.prototype;
vueProto[`$${name}`] = (dirty: string, opts = undefined) => sanitizeHtml(dirty, opts || options1);
chantouchsek commented 1 year ago

@danluchs feel free to submit a PR for support nuxt 3, I will take a look on it.

danluchs commented 12 months ago

@chantouchsek I'm not sure about the PR process, it doesn't look like I can make a branch?

The issue appears to be on line 55 in the src/sanitize.ts file. The following code should fix things. Nuxt 3/Vue 3 uses the config.globalProperties object vs. the old prototype object.

const vueProto = Vue?.config?.globalProperties ?? Vue.prototype;
vueProto[`$${name}`] = (dirty: string, opts = undefined) => sanitizeHtml(dirty, opts || options1);
chantouchsek commented 12 months ago

How did you try to create a branch?

chantouchsek commented 12 months ago

First fork it and commit from your repo

danluchs commented 12 months ago

OK, it's set up, ready for testing: https://github.com/chantouchsek/v-sanitize/pull/598

chantouchsek commented 11 months ago

@danluchs did you test on nuxt 3, I think it needs more change for that.