analytics-client
Advanced tools
Comparing version 1.6.0 to 1.7.0-getQueryString-expect-relative-url-57d6954a30b4ca2855946bff91d4034620c5910b
@@ -7,4 +7,9 @@ # Change Log | ||
# v1.7.0 | ||
## (2021-05-12) | ||
* Get getQueryString to expect relative URLs too [Ezequiel Boehler] | ||
# v1.6.0 | ||
## (2021-04-23) | ||
## (2021-04-22) | ||
@@ -11,0 +16,0 @@ * Added unsetParamsReferrerOnNewSession to client [Ezequiel Boehler] |
{ | ||
"name": "analytics-client", | ||
"version": "1.6.0", | ||
"version": "1.7.0-getQueryString-expect-relative-url-57d6954a30b4ca2855946bff91d4034620c5910b", | ||
"description": "Convenient builders to compose analytics tools", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -20,4 +20,4 @@ import { Client } from './client'; | ||
getSessionIdQueryString(): string; | ||
getQueryString(destinationUrl?: URL, currentUrl?: URL): string; | ||
getQueryString(destinationUrl?: URL | string, currentUrl?: URL): string; | ||
isOptOutRequested(): boolean; | ||
} |
@@ -112,2 +112,10 @@ "use strict"; | ||
AnalyticsUrlParams.prototype.getQueryString = function (destinationUrl, currentUrl) { | ||
var relativeRegex = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/g; | ||
if (typeof destinationUrl === 'string' && | ||
destinationUrl.match(relativeRegex)) { | ||
return ''; | ||
} | ||
if (typeof destinationUrl === 'string') { | ||
destinationUrl = new URL(destinationUrl); | ||
} | ||
var regex = /([a-zA-Z0-9-]+)(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]+$)/g; | ||
@@ -114,0 +122,0 @@ var actualDomainMatch; |
@@ -80,2 +80,5 @@ "use strict"; | ||
expect(urlParams.getQueryString(new URL('https://test.domain.edge.io'), new URL('https://domain2.edge.io'))).toBe(''); | ||
expect(urlParams.getQueryString('/etcher', new URL('https://domain2.edge.io'))).toBe(''); | ||
expect(urlParams.getQueryString('https://test.domain.io', new URL('https://domain.io'))).toBe(''); | ||
expect(urlParams.getQueryString('https://test.domain.io', new URL('https://otherdomain.com'))).toBe('d_id=d1&s_id=123'); | ||
}); | ||
@@ -82,0 +85,0 @@ var clientMock = function () { |
{ | ||
"name": "analytics-client", | ||
"version": "1.6.0", | ||
"version": "1.7.0-getQueryString-expect-relative-url-57d6954a30b4ca2855946bff91d4034620c5910b", | ||
"description": "Convenient builders to compose analytics tools", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -178,7 +178,20 @@ import * as Cookies from 'js-cookie'; | ||
*/ | ||
getQueryString(destinationUrl?: URL, currentUrl?: URL): string { | ||
getQueryString(destinationUrl?: URL | string, currentUrl?: URL): string { | ||
// we first check if destionationUrl is a relative URL string. If it is, we exit. | ||
const relativeRegex = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/g; | ||
if ( | ||
typeof destinationUrl === 'string' && | ||
destinationUrl.match(relativeRegex) | ||
) { | ||
return ''; | ||
} | ||
// If its not a relative URL string, we make sure if its a string or an URL. It its a string, we convert it to an URL object. | ||
if (typeof destinationUrl === 'string') { | ||
destinationUrl = new URL(destinationUrl); | ||
} | ||
// this regex is based on the assumption that we wont be using TLDs longer than 3 characters. If we do, it will break | ||
// the logic and take that longer TLD as the main domain, for example hub.balena.edge.io -> edge.io | ||
const regex = /([a-zA-Z0-9-]+)(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]+$)/g; | ||
let actualDomainMatch; | ||
@@ -185,0 +198,0 @@ if (currentUrl) { |
@@ -140,2 +140,23 @@ import { Client, createNoopClient } from '../src/client'; | ||
).toBe(''); | ||
// Case when passing a relative URL as destinationUrl | ||
expect( | ||
urlParams.getQueryString('/etcher', new URL('https://domain2.edge.io')), | ||
).toBe(''); | ||
// Case when passing an absolute URL as a string for destinationUrl and no passing is expected | ||
expect( | ||
urlParams.getQueryString( | ||
'https://test.domain.io', | ||
new URL('https://domain.io'), | ||
), | ||
).toBe(''); | ||
// Case when passing an absolute URL as a string for destinationUrl and passing is expected | ||
expect( | ||
urlParams.getQueryString( | ||
'https://test.domain.io', | ||
new URL('https://otherdomain.com'), | ||
), | ||
).toBe('d_id=d1&s_id=123'); | ||
}); | ||
@@ -142,0 +163,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
315394
2612
2