Skip to content
Open
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
6 changes: 5 additions & 1 deletion vtex/utils/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,10 +780,14 @@ export const legacyFacetToFilter = (
const map = hasToBeFullpath
? facet.Link.split("map=")[1].split(",")
: [facet.Map];
const value = hasToBeFullpath
let value = hasToBeFullpath
? facet.Link.split("?")[0].slice(1).split("/")
: [facet.Value];

if (hasToBeFullpath && value.some(v => /de-\d+-a-\d+-\d+/.test(v))) {
value = value.map(v => v.replace(/-(\d{2})$/, '.$1'));
}
Comment on lines +787 to +789
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Incomplete decimal separator normalization for price ranges.

The current logic only replaces the last hyphen-number pair (e.g., converting de-3490-a-5690 to de-3490-a-56.90), leaving the "from" price un-normalized. For consistency, both decimal separators should be converted.

Consider this fix to normalize both prices:

-    if (hasToBeFullpath && value.some(v => /de-\d+-a-\d+-\d+/.test(v))) {
-      value = value.map(v => v.replace(/-(\d{2})$/, '.$1'));
-    }
+    if (hasToBeFullpath && value.some(v => /^de-\d+-a-\d+$/.test(v))) {
+      value = value.map(v => v.replace(/^de-(\d+)(\d{2})-a-(\d+)(\d{2})$/, 'de-$1.$2-a-$3.$4'));
+    }

This assumes the format is de-[from_int][from_dec]-a-[to_int][to_dec] where the last 2 digits of each number represent the decimal part. If the format is different, please clarify with a comment and adjust the regex accordingly.

Verify the expected input format by running:


🏁 Script executed:

#!/bin/bash
# Description: Find examples of price range URLs in the codebase to understand the format

# Search for price range patterns in code and comments
rg -n -C3 "de-\d+-a-\d+" --type=ts

# Search for test files that might show expected formats
fd -e test.ts -e spec.ts -x rg -l "pricerange|price.range" {}

Length of output: 0



---

🏁 Script executed:

```shell
#!/bin/bash
# Read the actual file to see the code context and function

cat vtex/utils/transform.ts | head -850 | tail -70

Length of output: 2183


🏁 Script executed:

#!/bin/bash
# Search for test files and usage examples

fd -name "*.test.ts" -o -name "*.spec.ts" | head -20

# Search for references to legacyFacetToFilter or legacyFacetsNormalize
rg -n "legacyFacet|pricerange" --type=ts -i | head -40

Length of output: 8931


🏁 Script executed:

#!/bin/bash
# Search for patterns matching the code being reviewed

rg -n "hasToBeFullpath" --type=ts -C2 | head -50

Length of output: 1448



---

🏁 Script executed:

```shell
#!/bin/bash
# Read the legacyFacetsNormalize function to understand existing normalization

sed -n '897,920p' vtex/utils/transform.ts

Length of output: 944


🏁 Script executed:

#!/bin/bash
# Read the normalizeFacet function to see if it handles price normalization

sed -n '1034,1050p' vtex/utils/transform.ts

Length of output: 412


🏁 Script executed:

#!/bin/bash
# Search for test files or examples with price range patterns

find . -name "*.test.ts" -o -name "*.spec.ts" | xargs grep -l "de-.*-a-" 2>/dev/null || echo "No test files found with pattern"

# Search for comments or documentation about price format
rg -n "de-\d+" --type=ts -B2 -A2 | head -60

Length of output: 3181


🏁 Script executed:

#!/bin/bash
# Look for facet.Link examples in the codebase to understand the input format

rg -n "facet\.Link\|Link.*split" --type=ts -B1 -A1 | head -40

Length of output: 0


Incomplete decimal separator normalization for price ranges.

The current logic at lines 787-789 only replaces the last hyphen-number pair, leaving the "from" price un-normalized. For example, de-3490-a-5690 becomes de-3490-a-56.90 instead of de-34.90-a-56.90.

Consider this fix to normalize both prices:

-    if (hasToBeFullpath && value.some(v => /de-\d+-a-\d+-\d+/.test(v))) {
-      value = value.map(v => v.replace(/-(\d{2})$/, '.$1'));
-    }
+    if (hasToBeFullpath && value.some(v => /^de-\d+-a-\d+$/.test(v))) {
+      value = value.map(v => v.replace(/^de-(\d+)(\d{2})-a-(\d+)(\d{2})$/, 'de-$1.$2-a-$3.$4'));
+    }

This assumes the input format is de-[from_int][from_dec]-a-[to_int][to_dec] where the last 2 digits of each price represent the decimal part. The updated regex correctly transforms both price components, aligned with the expected format documented in legacyFacetsNormalize.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (hasToBeFullpath && value.some(v => /de-\d+-a-\d+-\d+/.test(v))) {
value = value.map(v => v.replace(/-(\d{2})$/, '.$1'));
}
if (hasToBeFullpath && value.some(v => /^de-\d+-a-\d+$/.test(v))) {
value = value.map(v => v.replace(/^de-(\d+)(\d{2})-a-(\d+)(\d{2})$/, 'de-$1.$2-a-$3.$4'));
}
🤖 Prompt for AI Agents
In vtex/utils/transform.ts around lines 787 to 789, the current mapping only
converts the trailing two digits of the "to" price to a decimal, leaving the
"from" price un-normalized; update the mapping so both price components are
normalized by replacing the final two-digit groups of each price with a
dot-prefixed decimal (i.e., convert both the two trailing digits before "-a-"
and the two trailing digits at the end), using a single replace call with a
regex that targets both positions and a replacement function that inserts the
'.' before the two-digit groups.


const pathSegmentsFiltered = hasProductClusterIds
? [pathSegments[mapSegments.indexOf("productClusterIds")]]
: [];
Expand Down