Skip to content

Fix address autocomplete duplicating city/state/country in Address 1#19062

Closed
jnMetaCode wants to merge 1 commit intotwentyhq:mainfrom
jnMetaCode:fix/address-autocomplete-format-18860
Closed

Fix address autocomplete duplicating city/state/country in Address 1#19062
jnMetaCode wants to merge 1 commit intotwentyhq:mainfrom
jnMetaCode:fix/address-autocomplete-format-18860

Conversation

@jnMetaCode
Copy link
Copy Markdown

Summary

  • Fixes the address autocomplete behavior where selecting a suggestion would store the full address string (e.g., "123 Main St, New York, NY 10001, USA") in the Address 1 field, even though city, state, postal code, and country were already extracted into their dedicated fields
  • After extracting address components from place details, the fix strips those components from the Address 1 text and cleans up leftover comma separators, so only the street address remains

Fixes #18860

Test plan

  • Open an address field and type a partial address in Address 1
  • Select an autocomplete suggestion from the dropdown
  • Verify that Address 1 contains only the street address (e.g., "123 Main St") and not the full string with city/state/country/zip
  • Verify that City, State, Post Code, and Country fields are still correctly populated
  • Test with addresses from different countries to confirm the cleanup handles various formats

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
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@github-actions
Copy link
Copy Markdown
Contributor

Welcome!

Hello there, congrats on your first PR! We're excited to have you contributing to this project.
By submitting your Pull Request, you acknowledge that you agree with the terms of our Contributor License Agreement.

Generated by 🚫 dangerJS against 4966f9c

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, '');
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 28, 2026

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
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>
Fix with Cubic

Comment on lines +93 to +95
for (const part of partsToRemove) {
cleanedStreet1 = cleanedStreet1.replace(part, '');
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

@charlesBochet
Copy link
Copy Markdown
Member

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre-filled addresses are not well formatted

2 participants