mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 18:26:20 +01:00
Filter subdomains in referrers regex test. Closes #632
This commit is contained in:
parent
e38f08b8f6
commit
7530de87d2
@ -1,5 +1,5 @@
|
||||
import { BROWSERS } from './constants';
|
||||
import { removeTrailingSlash, removeWWW, getDomainName } from './url';
|
||||
import { removeTrailingSlash, removeWWW } from './url';
|
||||
|
||||
export const urlFilter = (data, { raw }) => {
|
||||
const isValidUrl = url => {
|
||||
@ -46,23 +46,18 @@ export const urlFilter = (data, { raw }) => {
|
||||
};
|
||||
|
||||
export const refFilter = (data, { domain, domainOnly, raw }) => {
|
||||
const domainName = getDomainName(domain);
|
||||
const regex = new RegExp(`http[s]?://${domainName}`);
|
||||
const regex = new RegExp(`http[s]?://([a-z0-9-]+\\.)*${domain}`);
|
||||
const links = {};
|
||||
|
||||
const isValidRef = ref => {
|
||||
return ref !== '' && ref !== null && !ref.startsWith('/') && !ref.startsWith('#');
|
||||
};
|
||||
|
||||
if (raw) {
|
||||
return data.filter(({ x }) => isValidRef(x) && !regex.test(x));
|
||||
}
|
||||
|
||||
const cleanUrl = url => {
|
||||
try {
|
||||
const { hostname, origin, pathname, searchParams, protocol } = new URL(url);
|
||||
|
||||
if (hostname === domainName) {
|
||||
if (regex.test(url)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -88,6 +83,10 @@ export const refFilter = (data, { domain, domainOnly, raw }) => {
|
||||
}
|
||||
};
|
||||
|
||||
if (raw) {
|
||||
return data.filter(({ x }) => isValidRef(x) && !regex.test(x));
|
||||
}
|
||||
|
||||
const map = data.reduce((obj, { x, y }) => {
|
||||
if (!isValidRef(x)) {
|
||||
return obj;
|
||||
|
Loading…
Reference in New Issue
Block a user