Skip to content

Conversation

@ricardohenriquerh
Copy link

@ricardohenriquerh ricardohenriquerh commented Oct 23, 2025

fix price range input string

Summary by CodeRabbit

  • Bug Fixes
    • Improved processing and normalization of filter values in URLs, ensuring consistent handling of legacy-encoded segments during reconstruction.

@github-actions
Copy link
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.128.14 update
  • 🎉 for Minor 0.129.0 update
  • 🚀 for Major 1.0.0 update

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

Walkthrough

The legacyFacetToFilter function in vtex/utils/transform.ts has been modified to handle full-path filter values with updated derivation logic and new normalization. When hasToBeFullpath is true, the value is now computed by slicing and splitting the facet link, then segments matching a specific pattern are transformed by replacing trailing hyphens with dots.

Changes

Cohort / File(s) Summary
Full-path filter value normalization
vtex/utils/transform.ts
Modified legacyFacetToFilter function to declare value as mutable and alter its derivation when hasToBeFullpath is true; added regex-based segment normalization that transforms legacy-encoded patterns by replacing trailing hyphen-numbers with dot-numbers (e.g., -12.12)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A slash was trimmed, a segment born anew,
Hyphens dance to dots—the path shines through,
Facets transformed with careful precision,
Legacy URLs find their true vision! 🎯

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description provided is "fix price range input string," which is a single generic sentence that does not follow the required template structure at all. The repository template specifies required sections including "What is this Contribution About?", "Issue Link", "Loom Video", and "Demonstration Link", but none of these sections are present in the description. The brief description fails to provide meaningful context about what was changed, why it was changed, or how to verify the fix. This minimal effort description leaves reviewers without essential information needed for effective code review.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The PR title "fix: pricerangeinput" is concise and uses a conventional commit format. However, it lacks clarity and specificity about the actual change. While it does reference price range input which is related to the modifications in the transform utility, the title is too vague to clearly convey what the fix addresses. The raw summary indicates the changes involve normalizing legacy-encoded price/path segments during URL reconstruction and mutating filter values, but the title fails to communicate these specifics. A teammate scanning the git history would struggle to understand the core purpose of this change from the title alone.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
vtex/utils/transform.ts (2)

787-789: Add explanatory comments for the price range normalization logic.

The purpose and format of this transformation aren't immediately clear. Adding comments would help future maintainers understand why this normalization is necessary and what format it expects.

Apply this diff:

+    // Normalize price range format from legacy encoding (e.g., de-3490-a-5690)
+    // to decimal format (e.g., de-34.90-a-56.90) for full-path filters
     if (hasToBeFullpath && value.some(v => /de-\d+-a-\d+-\d+/.test(v))) {
       value = value.map(v => v.replace(/-(\d{2})$/, '.$1'));
     }

783-789: Document the relationship between price format normalization in legacyFacetToFilter and legacyFacetsNormalize.

These functions handle different price range formats in separate code paths. The new code in getLink (lines 783-789) transforms de-34-a-56-90 to de-34-a-56.90, while legacyFacetsNormalize (lines 897-911) transforms de-34,90-a-56,90 to 34.90:56.90. Add a comment explaining which format each normalizes and their distinct purposes to prevent future confusion.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1ae949 and d3a6fee.

📒 Files selected for processing (1)
  • vtex/utils/transform.ts (1 hunks)
🔇 Additional comments (1)
vtex/utils/transform.ts (1)

788-788: Remove this review comment - it is based on a false premise about VTEX's price format.

VTEX legacy URLs use a dot as the decimal separator with two decimal places, which is precisely what this transformation assumes. The code is specifically designed to handle VTEX price range facets from the API (used for PriceRanges in productListingPage.ts), not arbitrary prices. The precondition pattern /de-\d+-a-\d+-\d+/ is a VTEX-specific facet URL format, and the regex transformation aligns perfectly with VTEX's standard 2-decimal format. There is no risk of varying decimal places because the VTEX API enforces the standard format.

Likely an incorrect or invalid review comment.

Comment on lines +787 to +789
if (hasToBeFullpath && value.some(v => /de-\d+-a-\d+-\d+/.test(v))) {
value = value.map(v => v.replace(/-(\d{2})$/, '.$1'));
}
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.

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.

1 participant