fix fbclid url sanitizer
This commit is contained in:
@@ -19,7 +19,7 @@ const DOMPurify = require('dompurify')
|
|||||||
const { JSDOM } = require('jsdom')
|
const { JSDOM } = require('jsdom')
|
||||||
const { window } = new JSDOM('<!DOCTYPE html>')
|
const { window } = new JSDOM('<!DOCTYPE html>')
|
||||||
const domPurify = DOMPurify(window)
|
const domPurify = DOMPurify(window)
|
||||||
const url = require('url')
|
const URL = require('url')
|
||||||
|
|
||||||
domPurify.addHook('beforeSanitizeElements', node => {
|
domPurify.addHook('beforeSanitizeElements', node => {
|
||||||
if (node.hasAttribute && node.hasAttribute('href')) {
|
if (node.hasAttribute && node.hasAttribute('href')) {
|
||||||
@@ -29,7 +29,7 @@ domPurify.addHook('beforeSanitizeElements', node => {
|
|||||||
// remove FB tracking param
|
// remove FB tracking param
|
||||||
if (href.includes('fbclid=')) {
|
if (href.includes('fbclid=')) {
|
||||||
try {
|
try {
|
||||||
const url = new url.URL(href)
|
const url = new URL.URL(href)
|
||||||
url.searchParams.delete('fbclid')
|
url.searchParams.delete('fbclid')
|
||||||
node.setAttribute('href', url.href)
|
node.setAttribute('href', url.href)
|
||||||
if (text.includes('fbclid=')) {
|
if (text.includes('fbclid=')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user