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

Does not work when used through a Vue Mixin #39

Open
brian-gonzalez opened this issue Mar 1, 2022 · 1 comment
Open

Does not work when used through a Vue Mixin #39

brian-gonzalez opened this issue Mar 1, 2022 · 1 comment

Comments

@brian-gonzalez
Copy link

Hello!

We have a setup where we share a mixin through multiple Vue components, and were hoping that this plugin would work with said structure.

This is a sample of the configuration:

The mixin:

import DOMPurify from "dompurify";

export default {
  props: {
    description: {
      type: String,
      default: "",
    },
  },
  computed: {
    sanitizedDescription() {
      return DOMPurify.sanitize(this.description);
    },
  },
};

A component (:

<template>
    <div v-html="sanitizedDescription"></div>
</template>

<script>
    import TextMixin from "path/to/text/mixin";

    export default {
        name: "ComponentName",
        mixins: [ TextMixin ],
    }
</script>

Using this approach we get the eslint error: "XSS potentially found: use of v-html"

Of course, adding the computed functions within each component does work as intended, but we wanted to see if it was possible to reduce repeated code.

Thanks!

@axtho
Copy link

axtho commented Nov 11, 2022

The same applies to composeables in Vue 3.

Example:

// composeables.ts
import DOMPurify from "dompurify";

function useSanitize(html: string): string {
  return DOMPurify.sanitize(html);
}

// MyOptions.vue
<script setup>
import { useSanitize } from "@/common/wrappers";

const props = ...

</script>
<template>
  <div>
    <span v-html="useSanitize(props.text)"></span>
 </div>
</template>

This setup will cause a lint error (yarn lint).
VSCode still displays it as a warning, even when I import DOMPurify and create a local function to sanitize (which removes the lint error/ warning in the console).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants