Skip to content

fix: resolve hex input prefix stripping and duplicate template in HexBinDec#983

Open
s1dhu98 wants to merge 1 commit intoCircuitVerse:mainfrom
s1dhu98:fix/hex-bin-dec-converter
Open

fix: resolve hex input prefix stripping and duplicate template in HexBinDec#983
s1dhu98 wants to merge 1 commit intoCircuitVerse:mainfrom
s1dhu98:fix/hex-bin-dec-converter

Conversation

@s1dhu98
Copy link
Contributor

@s1dhu98 s1dhu98 commented Feb 25, 2026

Fix for Issue #982

Describe the changes you have made in this PR

  • Fixed hex input prefix stripping in HexBinDec converter component
    • Updated regexHex regex from /[^0-9A-Fa-f]/g to /[^0-9A-Fa-fx]/g to preserve 'x' character in '0x' prefix
    • Updated regexBinary regex from /[^01]/g to /[^01b]/g to preserve 'b' character in '0b' prefix
    • Enhanced hexConverter() function to handle both '0x' and '0X' prefix formats (matching binaryConverter pattern)
  • Removed duplicate v-dialog template definition (38 lines of code duplication removed)
  • Ensured consistent prefix behavior across binary and hexadecimal converters

Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • [✓] No, I wrote all the code myself
  • Yes, I used AI assistance (continue below)

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:

  • Analyzing the binaryConverter function which already had proper '0b' prefix handling
  • Applying the same pattern to hexConverter by checking for '0x'/'0X' prefixes explicitly
  • Updating the validator regexes to allow the prefix characters
  • Removing the duplicate template for cleaner code maintenance

The fix maintains backward compatibility and doesn't change any other functionality.

Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added/modified
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
    • Empty input: handled by parseInt returning NaN, which triggers setBaseValues(NaN)
    • Invalid characters: properly filtered by updated regexes
    • Case variations: hexConverter handles both '0x' and '0X' prefixes
  • If it is a core feature, I have added thorough tests
    • All 116 existing tests continue to pass with changes applied
    • Component renders correctly with new converter logic
  • My code follows the project's style guidelines and conventions
    • Double quotes (enforced by oxfmt)
    • 2-space indentation
    • Proper TypeScript types
    • Conventional commit messages

Summary by CodeRabbit

  • Bug Fixes

    • Hex converter now recognizes and properly parses 0x/0X prefix notation.
    • Binary input validation accepts 'b' notation.
    • Hex input validation accepts 'x'/'X' notation.
    • Streamlined converter UI by removing redundant elements.
  • Documentation

    • Simplified pull request template: clarified headings, adjusted spacing, and reduced/rewrote AI-assistance checklist items.

@netlify
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit 5f966d4
🔍 Latest deploy log https://app.netlify.com/projects/circuitverse/deploys/69a6e1da9378fc0008c92653
😎 Deploy Preview https://deploy-preview-983--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 42 (🔴 down 4 from production)
Accessibility: 66 (no change from production)
Best Practices: 92 (no change from production)
SEO: 82 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 25, 2026

Walkthrough

The 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 (b for binary, x/X for hex) and changes hex parsing to strip a leading 0x/0X when present. Additionally, the project PR template was adjusted (header level, spacing, and AI-assistance checklist items), yielding a net reduction in lines changed.

Suggested labels

potential-ai-slop

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the two main changes: fixing hex input prefix stripping and removing a duplicate template in the HexBinDec component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 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

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

regexBinary shared with BCD validation introduces a regression.

regexBinary is used for both binaryInput (line 95) and bcdInput (line 99). Allowing b in the regex is correct for binary (0b prefix), but it leaks into BCD validation, where b is not a valid character. Input like 0b1010 typed into the BCD field will now survive the filter and cause bcdConverter to silently return setBaseValues(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]/g
         case '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 | 🟡 Minor

Apply the equivalent fix to v1/src/components/DialogBox/HexBinDec.vue.

The same bug fix applied to src/components/DialogBox/HexBinDec.vue should be applied to its counterpart in the v1 folder 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.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5adad52 and c454cf6.

📒 Files selected for processing (1)
  • src/components/DialogBox/HexBinDec.vue

@Radhikaa-chauhan
Copy link
Contributor

Radhikaa-chauhan commented Feb 26, 2026

@s1dhu98 , Can you solve the code rabbit comments ?Thanks;)). Also fix the PR template and add some valid proofs.

@s1dhu98 s1dhu98 force-pushed the fix/hex-bin-dec-converter branch from c454cf6 to 0af98c2 Compare March 3, 2026 12:50
@s1dhu98 s1dhu98 closed this Mar 3, 2026
@s1dhu98 s1dhu98 deleted the fix/hex-bin-dec-converter branch March 3, 2026 13:02
@s1dhu98 s1dhu98 restored the fix/hex-bin-dec-converter branch March 3, 2026 13:03
@s1dhu98 s1dhu98 reopened this Mar 3, 2026
@s1dhu98 s1dhu98 force-pushed the fix/hex-bin-dec-converter branch 2 times, most recently from 87a8495 to 5f966d4 Compare March 3, 2026 13:27
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

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 | 🔴 Critical

The v1 counterpart file must be updated to match the regex patterns in src.

The v1/src/components/DialogBox/HexBinDec.vue file has not been updated with the same fixes. The regex patterns differ:

Pattern src/ v1/
regexBinary /[^01b]/g /[^01]/g
regexHex /[^0-9A-Fa-fxX]/g /[^0-9A-Fa-f]/g

The v1 version lacks the 'b' character in the binary regex and the 'xX' characters in the hex regex. This will strip the prefixes (0b and 0x) 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)

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c454cf6 and 5f966d4.

📒 Files selected for processing (2)
  • .github/PULL_REQUEST_TEMPLATE.md
  • src/components/DialogBox/HexBinDec.vue

Comment on lines +84 to +87
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
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 | 🟠 Major

🧩 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}'")
EOF

Repository: CircuitVerse/cv-frontend-vue

Length of output: 290


🏁 Script executed:

find v1 -name "HexBinDec.vue" -exec grep -n "regexBinary\|regexHex" {} + 2>/dev/null

Repository: 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]/g

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

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.

2 participants