Skip to content

Commit 36ddba2

Browse files
Release build 4.64.0 [ci release]
1 parent 2c0a563 commit 36ddba2

File tree

9 files changed

+240
-18
lines changed

9 files changed

+240
-18
lines changed

Sources/ContentScopeScripts/dist/contentScope.js

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Sources/ContentScopeScripts/dist/contentScopeIsolated.js

Lines changed: 40 additions & 3 deletions
Large diffs are not rendered by default.

build/android/contentScope.js

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

build/contentScope.js

Lines changed: 40 additions & 3 deletions
Large diffs are not rendered by default.

build/integration/contentScope.js

Lines changed: 40 additions & 3 deletions
Large diffs are not rendered by default.

build/tracker-lookup.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

build/windows/contentScope.js

Lines changed: 40 additions & 3 deletions
Large diffs are not rendered by default.

src/features/broker-protection/actions/extract.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { matchAddressFromAddressListCityState } from '../comparisons/address.js'
1111
*/
1212

1313
/**
14+
* @typedef {'param'|'path'} IdentifierType
1415
* @typedef {Object} ExtractProfileProperty
1516
* For example: {
1617
* "selector": ".//div[@class='col-sm-24 col-md-8 relatives']//li"
@@ -20,6 +21,8 @@ import { matchAddressFromAddressListCityState } from '../comparisons/address.js'
2021
* @property {string} [afterText] - get all text after this string
2122
* @property {string} [beforeText] - get all text before this string
2223
* @property {string} [separator] - split the text on this string
24+
* @property {IdentifierType} [identifierType] - the type (path/param) of the identifier
25+
* @property {string} [identifier] - the identifier itself (either a param name, or a templated URI)
2326
*/
2427

2528
/**
@@ -191,7 +194,7 @@ export function aggregateFields (profile) {
191194
addresses,
192195
phoneNumbers,
193196
relatives: profile.relativesList,
194-
profileUrl: profile.profileUrl
197+
...profile.profileUrl
195198
}
196199
}
197200

@@ -239,7 +242,21 @@ function extractValue (key, value, elementValue) {
239242
return stringToList(phoneNumber)
240243
},
241244
phoneList: () => stringToList(elementValue, value.separator),
242-
relativesList: () => stringToList(elementValue, value.separator)
245+
relativesList: () => stringToList(elementValue, value.separator),
246+
profileUrl: () => {
247+
const profile = {
248+
profileUrl: elementValue,
249+
identifier: elementValue
250+
}
251+
252+
if (!value.identifierType || !value.identifier) {
253+
return profile
254+
}
255+
256+
const profileUrl = Array.isArray(elementValue) ? elementValue[0] : elementValue
257+
profile.identifier = getIdFromProfileUrl(profileUrl, value.identifierType, value.identifier)
258+
return profile
259+
}
243260
}
244261

245262
if (key in extractors) {
@@ -302,3 +319,23 @@ const rules = {
302319
return link?.href ?? null
303320
}
304321
}
322+
323+
/**
324+
* Parse a profile id from a profile URL
325+
* @param {string} profileUrl
326+
* @param {IdentifierType} identifierType
327+
* @param {string} identifier
328+
* @return {string}
329+
*/
330+
export function getIdFromProfileUrl (profileUrl, identifierType, identifier) {
331+
const parsedUrl = new URL(profileUrl)
332+
const urlParams = parsedUrl.searchParams
333+
334+
// Attempt to parse out an id from the search parameters
335+
if (identifierType === 'param' && urlParams.has(identifier)) {
336+
const profileId = urlParams.get(identifier)
337+
return profileId || profileUrl
338+
}
339+
340+
return profileUrl
341+
}

unit-test/broker-protection.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fc from 'fast-check'
22
import { isSameAge } from '../src/features/broker-protection/comparisons/is-same-age.js'
33
import { getNicknames, isSameName } from '../src/features/broker-protection/comparisons/is-same-name.js'
4-
import { getCityStateCombos, stringToList } from '../src/features/broker-protection/actions/extract.js'
4+
import { getCityStateCombos, stringToList, getIdFromProfileUrl } from '../src/features/broker-protection/actions/extract.js'
55
import {
66
matchAddressCityState,
77
matchAddressFromAddressListCityState
@@ -211,6 +211,43 @@ describe('Actions', () => {
211211
})
212212
})
213213
})
214+
215+
describe('getIdFromProfileUrl', () => {
216+
it('should return the profile URL as the identifier if the identifierType is "path"', () => {
217+
const profileUrl = 'https://duckduckgo.com/my/profile/john-smith/223'
218+
const identifierType = 'path'
219+
// eslint-disable-next-line no-template-curly-in-string
220+
const identifier = 'https://duckduckgo.com/my/profile/${firstName}-${lastName}/${id}'
221+
222+
expect(getIdFromProfileUrl(profileUrl, identifierType, identifier)).toEqual(profileUrl)
223+
})
224+
225+
it('should return the profile URL as the identifier if the identifierType is "param" and the param is not found', () => {
226+
const profileUrl = 'https://duckduckgo.com/my/profile?id=test'
227+
const identifierType = 'param'
228+
const identifier = 'pid'
229+
230+
expect(getIdFromProfileUrl(profileUrl, identifierType, identifier)).toEqual(profileUrl)
231+
})
232+
233+
it('should return the profile URL as the identifier if the identifierType is "param" and the identifier is a path', () => {
234+
const profileUrl = 'https://duckduckgo.com/my/profile/john-smith/223'
235+
const identifierType = 'param'
236+
// eslint-disable-next-line no-template-curly-in-string
237+
const identifier = 'https://duckduckgo.com/my/profile/${firstName}-${lastName}/${id}'
238+
239+
expect(getIdFromProfileUrl(profileUrl, identifierType, identifier)).toEqual(profileUrl)
240+
})
241+
242+
it('should return the id as the identifier if the identifierType is "param" and the param is found in the url', () => {
243+
const id = 'test'
244+
const profileUrl = `https://duckduckgo.com/my/profile?id=${id}`
245+
const identifierType = 'param'
246+
const identifier = 'id'
247+
248+
expect(getIdFromProfileUrl(profileUrl, identifierType, identifier)).toEqual(id)
249+
})
250+
})
214251
})
215252

216253
describe('buildUrl', () => {

0 commit comments

Comments
 (0)