Domain validation. Filter domain from referrers.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import firstBy from 'thenby';
|
||||
import { BROWSERS, ISO_COUNTRIES, DEVICES } from './constants';
|
||||
import { removeTrailingSlash } from './format';
|
||||
import { removeTrailingSlash, getDomainName } from './url';
|
||||
|
||||
export const urlFilter = (data, { domain, raw }) => {
|
||||
export const urlFilter = (data, { raw }) => {
|
||||
const isValidUrl = url => {
|
||||
return url !== '' && !url.startsWith('#');
|
||||
};
|
||||
@@ -30,7 +30,7 @@ export const urlFilter = (data, { domain, raw }) => {
|
||||
return obj;
|
||||
}
|
||||
|
||||
const url = cleanUrl(x.startsWith('/') ? `http://${domain}${x}` : x);
|
||||
const url = cleanUrl(`http://x${x}`);
|
||||
|
||||
if (url) {
|
||||
if (!obj[url]) {
|
||||
@@ -49,7 +49,8 @@ export const urlFilter = (data, { domain, raw }) => {
|
||||
};
|
||||
|
||||
export const refFilter = (data, { domain, domainOnly, raw }) => {
|
||||
const regex = new RegExp(domain.startsWith('http') ? domain : `http[s]?://${domain}`);
|
||||
const domainName = getDomainName(domain);
|
||||
const regex = new RegExp(`http[s]?://${domainName}`);
|
||||
|
||||
const isValidRef = ref => {
|
||||
return ref !== '' && !ref.startsWith('/') && !ref.startsWith('#');
|
||||
@@ -63,7 +64,7 @@ export const refFilter = (data, { domain, domainOnly, raw }) => {
|
||||
try {
|
||||
const { hostname, origin, pathname, searchParams, protocol } = new URL(url);
|
||||
|
||||
if (hostname === domain || regex.test(url)) {
|
||||
if (hostname === domainName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user