Skip to content

Commit

Permalink
Support textNodes, remove commas from the end of addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhall committed Jan 29, 2025
1 parent 8e76460 commit fcedecd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions injected/src/features/broker-protection/actions/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,20 @@ export function createProfile(elementFactory, extractData) {
}

/**
* @param {{innerText: string}[]} elements
* @param {(HTMLElement | { innerText: string })[]} elements
* @param {string} key
* @param {ExtractProfileProperty} extractField
* @return {string[]}
*/
function stringValuesFromElements(elements, key, extractField) {
return elements.map((element) => {
// todo: should we use textContent here?
let elementValue = rules[key]?.(element) ?? element?.innerText ?? null;
let elementValue;

if ('nodeType' in element && element.nodeType === Node.TEXT_NODE) {
elementValue = element.textContent;
} else {
elementValue = rules[key]?.(element) ?? element?.innerText ?? null;
}

if (extractField?.afterText) {
elementValue = elementValue?.split(extractField.afterText)[1]?.trim() || elementValue;
Expand Down
3 changes: 3 additions & 0 deletions injected/src/features/broker-protection/extractors/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ function getCityStateCombos(inputList) {
// Strip out the zip code since we're only interested in city/state here.
item = item.replace(/,?\s*\d{5}(-\d{4})?/, '');

// Replace any commas at the end of the string that could confuse the city/state split.
item = item.replace(/,$/, '');

if (item.includes(',')) {
words = item.split(',').map((item) => item.trim());
} else {
Expand Down

0 comments on commit fcedecd

Please sign in to comment.