Fix address autocomplete duplicating city/state/country in Address 1#19062
Fix address autocomplete duplicating city/state/country in Address 1#19062jnMetaCode wants to merge 1 commit intotwentyhq:mainfrom
Conversation
When selecting an address from autocomplete suggestions, the full address string (including city, state, postal code, and country) was being stored in the Address 1 field even though those components were already extracted into their dedicated fields. This caused duplicate display of address parts. Strip the extracted city, state, postal code, and country from the Address 1 field after they have been parsed into separate fields, and clean up any leftover comma separators. Fixes twentyhq#18860
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
Welcome!
Hello there, congrats on your first PR! We're excited to have you contributing to this project. |
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/twenty-front/src/modules/ui/field/input/hooks/useAddressAutocomplete.ts">
<violation number="1" location="packages/twenty-front/src/modules/ui/field/input/hooks/useAddressAutocomplete.ts:94">
P1: Global substring replacement can corrupt Address 1 by deleting valid street text when component values also appear in the street name.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| ].filter(isDefined); | ||
|
|
||
| for (const part of partsToRemove) { | ||
| cleanedStreet1 = cleanedStreet1.replace(part, ''); |
There was a problem hiding this comment.
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
Check if this issue is valid — if so, understand the root cause and fix it. At packages/twenty-front/src/modules/ui/field/input/hooks/useAddressAutocomplete.ts, line 94:
<comment>Global substring replacement can corrupt Address 1 by deleting valid street text when component values also appear in the street name.</comment>
<file context>
@@ -79,8 +79,30 @@ export const useAddressAutocomplete = (
+ ].filter(isDefined);
+
+ for (const part of partsToRemove) {
+ cleanedStreet1 = cleanedStreet1.replace(part, '');
+ }
+
</file context>
| for (const part of partsToRemove) { | ||
| cleanedStreet1 = cleanedStreet1.replace(part, ''); | ||
| } |
There was a problem hiding this comment.
Bug: The street cleaning logic incorrectly modifies street names that contain substrings of the city, state, or country by using String.prototype.replace() instead of a more precise removal method.
Severity: HIGH
Suggested Fix
To 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 (\b) to ensure only whole words are replaced, or anchor the replacement to the end of the string if the components to be removed are always at the end.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location:
packages/twenty-front/src/modules/ui/field/input/hooks/useAddressAutocomplete.ts#L93-L95
Potential issue: The street cleaning logic in `useAddressAutocomplete.ts` uses
`String.prototype.replace()` to remove extracted address components like city, state,
and postcode from the main address string. This method only replaces the first literal
substring match. If a street name contains the name of the city (e.g., "New York Ave" in
the city of "York"), the street name itself will be incorrectly modified, leading to
corrupted address data. For example, an address like "123 New York Ave, York, PA" would
be incorrectly changed to "123 New Ave". This issue affects real-world addresses where
such name overlaps are common.
Did we get this right? 👍 / 👎 to inform future reviews.
|
@jnMetaCode Please stop opening AI generated PR on this repository. You are not helping us and harming the community. This will be the only warning before ban: one more and that's it |
Summary
Fixes #18860
Test plan