fix: resolve hex input prefix stripping and duplicate template in HexBinDec#983
fix: resolve hex input prefix stripping and duplicate template in HexBinDec#983s1dhu98 wants to merge 1 commit intoCircuitVerse:mainfrom
Conversation
✅ Deploy Preview for circuitverse ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
WalkthroughThe PR removes a duplicate Hex-Bin-Dec converter dialog from the component template, deleting its header, close button, inputs, reset button, and associated DOM wiring. It updates input validation regexes to allow prefix characters ( Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/components/DialogBox/HexBinDec.vue (2)
84-99:⚠️ Potential issue | 🟠 Major
regexBinaryshared with BCD validation introduces a regression.
regexBinaryis used for bothbinaryInput(line 95) andbcdInput(line 99). Allowingbin the regex is correct for binary (0bprefix), but it leaks into BCD validation, wherebis not a valid character. Input like0b1010typed into the BCD field will now survive the filter and causebcdConverterto silently returnsetBaseValues(NaN)instead of producing a correct result.Use a separate, stricter regex for BCD:
🐛 Proposed fix
- const regexBinary = /[^01b]/g + const regexBinary = /[^01b]/g // for binaryInput (0b prefix allowed) + const regexBcd = /[^01]/g // for bcdInput (no prefix, strict) const regexOctal = /[^0-7]/g const regexDecimal = /[^0-9]/g const regexHex = /[^0-9A-Fa-fx]/gcase 'bcdInput': - value = value.replace(regexBinary, '') + value = value.replace(regexBcd, '') bcdConverter(value) break🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/DialogBox/HexBinDec.vue` around lines 84 - 99, The BCD input is being filtered with regexBinary (which allows 'b' for 0b prefixes) causing invalid 'b' characters to pass into bcdConverter and produce NaN; create a stricter regex (e.g., regexBcd that only allows '0' and '1') and use it when handling the bcdInput case instead of regexBinary so bcdConverter receives only valid BCD characters; update the switch case for 'bcdInput' to replace using regexBcd and then call bcdConverter(value).
84-179:⚠️ Potential issue | 🟡 MinorApply the equivalent fix to
v1/src/components/DialogBox/HexBinDec.vue.The same bug fix applied to
src/components/DialogBox/HexBinDec.vueshould be applied to its counterpart in thev1folder in this PR, as per the project convention for bug fixes across both versions.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/DialogBox/HexBinDec.vue` around lines 84 - 179, Open v1/src/components/DialogBox/HexBinDec.vue and apply the same fixes you made in src/components/DialogBox/HexBinDec.vue: update the input-cleaning regexes and the switch(target.id) handling, and ensure convertToBCD, setBaseValues, decimalConverter, binaryConverter, bcdConverter, octalConverter, and hexConverter have the identical corrected logic (including prefix handling like '0b'/'0x' and NaN handling) so both versions behave the same.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/DialogBox/HexBinDec.vue`:
- Line 87: The regexHex currently defined as regexHex in HexBinDec.vue excludes
uppercase "X", which causes the hexConverter branch that checks for a "0X"
prefix to never run; update the regexHex pattern to allow uppercase X (include
"X" in the allowed character class) so inputs like "0X1A" are not stripped, or
alternatively remove the manual prefix-stripping logic in hexConverter and pass
the raw input directly to parseInt(input, 16) which accepts both "0x" and "0X".
---
Outside diff comments:
In `@src/components/DialogBox/HexBinDec.vue`:
- Around line 84-99: The BCD input is being filtered with regexBinary (which
allows 'b' for 0b prefixes) causing invalid 'b' characters to pass into
bcdConverter and produce NaN; create a stricter regex (e.g., regexBcd that only
allows '0' and '1') and use it when handling the bcdInput case instead of
regexBinary so bcdConverter receives only valid BCD characters; update the
switch case for 'bcdInput' to replace using regexBcd and then call
bcdConverter(value).
- Around line 84-179: Open v1/src/components/DialogBox/HexBinDec.vue and apply
the same fixes you made in src/components/DialogBox/HexBinDec.vue: update the
input-cleaning regexes and the switch(target.id) handling, and ensure
convertToBCD, setBaseValues, decimalConverter, binaryConverter, bcdConverter,
octalConverter, and hexConverter have the identical corrected logic (including
prefix handling like '0b'/'0x' and NaN handling) so both versions behave the
same.
|
@s1dhu98 , Can you solve the code rabbit comments ?Thanks;)). Also fix the PR template and add some valid proofs. |
c454cf6 to
0af98c2
Compare
87a8495 to
5f966d4
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/DialogBox/HexBinDec.vue (1)
84-178:⚠️ Potential issue | 🔴 CriticalThe
v1counterpart file must be updated to match the regex patterns insrc.The
v1/src/components/DialogBox/HexBinDec.vuefile has not been updated with the same fixes. The regex patterns differ:
Pattern src/v1/regexBinary /[^01b]/g/[^01]/gregexHex /[^0-9A-Fa-fxX]/g/[^0-9A-Fa-f]/gThe v1 version lacks the 'b' character in the binary regex and the 'xX' characters in the hex regex. This will strip the prefixes (
0band0x) from user input, causing the converters to fail. Update v1 to match the src patterns.
🧹 Nitpick comments (1)
.github/PULL_REQUEST_TEMPLATE.md (1)
7-7: Consider replacing the empty bullet with a guided placeholder.Line 7 currently renders a blank list item in new PRs; a short prompt is clearer for contributors.
✏️ Suggested tweak
-- +- Briefly summarize the concrete code changes (module/function + behavior impact)
| const regexBinary = /[^01b]/g | ||
| const regexOctal = /[^0-7]/g | ||
| const regexDecimal = /[^0-9]/g | ||
| const regexHex = /[^0-9A-Fa-f]/g | ||
| const regexHex = /[^0-9A-Fa-fxX]/g |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n src/components/DialogBox/HexBinDec.vue | sed -n '80,95p'Repository: CircuitVerse/cv-frontend-vue
Length of output: 689
🏁 Script executed:
cat -n src/components/DialogBox/HexBinDec.vue | sed -n '168,182p'Repository: CircuitVerse/cv-frontend-vue
Length of output: 472
🏁 Script executed:
cat -n src/components/DialogBox/HexBinDec.vue | sed -n '1,50p'Repository: CircuitVerse/cv-frontend-vue
Length of output: 2162
🏁 Script executed:
cat -n src/components/DialogBox/HexBinDec.vue | sed -n '100,170p'Repository: CircuitVerse/cv-frontend-vue
Length of output: 2377
🏁 Script executed:
fd HexBinDec src/v1 v1 2>/dev/null || echo "No v1 folder found"Repository: CircuitVerse/cv-frontend-vue
Length of output: 113
🏁 Script executed:
cat -n v1/src/components/DialogBox/HexBinDec.vue | sed -n '80,95p'Repository: CircuitVerse/cv-frontend-vue
Length of output: 616
🏁 Script executed:
python3 << 'EOF'
# Test parseInt behavior with malformed inputs
# JavaScript parseInt stops at first invalid character for the radix
# Simulating parseInt(input, radix) behavior
def test_parse(input_str, radix):
"""Simulate parseInt behavior - stops at first invalid char for radix"""
import re
if radix == 2:
valid_chars = '01'
elif radix == 16:
valid_chars = '0123456789ABCDEFabcdef'
else:
return None
# parseInt extracts leading valid chars
result = ''
for char in input_str:
if char.lower() in valid_chars.lower():
result += char
else:
break # stops at first invalid
return result if result else None
# Test cases from the review
test_cases = [
("101b1", 2), # Binary with 'b' in middle
("1b01", 2), # Binary with 'b' early
("1x2", 16), # Hex with 'x' in middle
("ff", 16), # Valid hex
("0x1a", 16), # Hex with prefix
]
print("Test parseInt-like behavior:")
for input_val, radix in test_cases:
parsed = test_parse(input_val, radix)
radix_name = "binary" if radix == 2 else "hex"
print(f" Input: '{input_val}' (radix {radix}/{radix_name}) → '{parsed}'")
EOFRepository: CircuitVerse/cv-frontend-vue
Length of output: 290
🏁 Script executed:
find v1 -name "HexBinDec.vue" -exec grep -n "regexBinary\|regexHex" {} + 2>/dev/nullRepository: CircuitVerse/cv-frontend-vue
Length of output: 311
🏁 Script executed:
cat -n v1/src/components/DialogBox/HexBinDec.vue | sed -n '100,180p'Repository: CircuitVerse/cv-frontend-vue
Length of output: 2808
Remove 'b' and 'x/X' from sanitization regexes to match v1 version and prevent silent data loss.
The src/ version allows b and x/X anywhere in the input via the regexes (lines 84 and 87), but the v1 version correctly omits these characters. This creates a critical parity mismatch: when users type malformed inputs like 101b1 or 1x2, the regex keeps these characters, and parseInt() silently truncates at the first invalid character for that radix, losing data (e.g., parseInt("101b1", 2) parses only "101").
The v1 regexes (/[^01]/g and /[^0-9A-Fa-f]/g) are correct. The explicit prefix handling already exists in binaryConverter() (lines 140–148) and hexConverter() (lines 172–180), so the input sanitization only needs to strip non-digit characters for each base.
Minimal fix
- const regexBinary = /[^01b]/g
+ const regexBinary = /[^01]/g
- const regexHex = /[^0-9A-Fa-fxX]/g
+ const regexHex = /[^0-9A-Fa-f]/gThis also fixes bcdInput (line 99), which reuses regexBinary and would fail if 'b' characters were present.
Ensure the same changes are applied to v1/src/components/DialogBox/HexBinDec.vue for consistency, even though v1 already has the correct patterns.

Fix for Issue #982
Describe the changes you have made in this PR
/[^0-9A-Fa-f]/gto/[^0-9A-Fa-fx]/gto preserve 'x' character in '0x' prefix/[^01]/gto/[^01b]/gto preserve 'b' character in '0b' prefixCode Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
Explain your implementation approach:
The HexBinDec converter component had two bugs: (1) the hexadecimal input regex was stripping the 'x' character from the '0x' prefix, and (2) the v-dialog template was duplicated.
I fixed this by:
The fix maintains backward compatibility and doesn't change any other functionality.
Checklist before requesting a review
Summary by CodeRabbit
Bug Fixes
Documentation