-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fix address autocomplete duplicating city/state/country in Address 1 #19062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,8 +79,30 @@ export const useAddressAutocomplete = ( | |
| const placeData = await getPlaceDetailsData(placeId, token); | ||
| const countryName = findCountryNameByCountryCode(placeData?.country); | ||
|
|
||
| let cleanedStreet1 = | ||
| addressStreet1 || (internalValue?.addressStreet1 ?? ''); | ||
|
|
||
| if (isDefined(addressStreet1)) { | ||
| const partsToRemove = [ | ||
| placeData?.city, | ||
| placeData?.state, | ||
| placeData?.postcode, | ||
| countryName, | ||
| ].filter(isDefined); | ||
|
|
||
| for (const part of partsToRemove) { | ||
| cleanedStreet1 = cleanedStreet1.replace(part, ''); | ||
| } | ||
|
Comment on lines
+93
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The street cleaning logic incorrectly modifies street names that contain substrings of the city, state, or country by using Suggested FixTo prevent incorrect substring replacement, use a more precise method to remove the unwanted parts. One approach is to split the full address string by the comma separator, take the first element (the street), and trim any whitespace. Alternatively, use a regular expression with word boundaries ( Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
|
|
||
| cleanedStreet1 = cleanedStreet1 | ||
| .replace(/,\s*,/g, ',') | ||
| .replace(/,\s*$/, '') | ||
| .replace(/^\s*,/, '') | ||
| .trim(); | ||
| } | ||
|
|
||
| const updatedAddress = { | ||
| addressStreet1: addressStreet1 || (internalValue?.addressStreet1 ?? ''), | ||
| addressStreet1: cleanedStreet1, | ||
| addressStreet2: internalValue?.addressStreet2 ?? null, | ||
| addressCity: placeData?.city || (internalValue?.addressCity ?? null), | ||
| addressState: placeData?.state || (internalValue?.addressState ?? null), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Global substring replacement can corrupt Address 1 by deleting valid street text when component values also appear in the street name.
Prompt for AI agents