Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
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
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.


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),
Expand Down
Loading