fix fbclid url sanitizer

This commit is contained in:
lesion 2023-02-08 09:20:48 +01:00
parent ce82e8477c
commit fa91646a6a
No known key found for this signature in database
GPG key ID: 352918250B012177

View file

@ -19,7 +19,7 @@ const DOMPurify = require('dompurify')
const { JSDOM } = require('jsdom')
const { window } = new JSDOM('<!DOCTYPE html>')
const domPurify = DOMPurify(window)
const url = require('url')
const URL = require('url')
domPurify.addHook('beforeSanitizeElements', node => {
if (node.hasAttribute && node.hasAttribute('href')) {
@ -29,7 +29,7 @@ domPurify.addHook('beforeSanitizeElements', node => {
// remove FB tracking param
if (href.includes('fbclid=')) {
try {
const url = new url.URL(href)
const url = new URL.URL(href)
url.searchParams.delete('fbclid')
node.setAttribute('href', url.href)
if (text.includes('fbclid=')) {