Skip to content

Commit c454cf6

Browse files
committed
fix: resolve hex input prefix stripping and duplicate template in HexBinDec
- Remove '0x' prefix stripping by updating regexHex to include 'x' character - Add 'b' character to regexBinary to preserve '0b' prefix - Implement hexConverter prefix handling for both '0x' and '0X' formats - Remove duplicate v-dialog template definition (lines 43-84) - Ensure consistent prefix behavior across binary and hex converters - All 116 tests pass with changes applied Closes #982
1 parent 5adad52 commit c454cf6

File tree

1 file changed

+8
-46
lines changed

1 file changed

+8
-46
lines changed

src/components/DialogBox/HexBinDec.vue

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -42,49 +42,6 @@
4242
</v-card-actions>
4343
</v-card>
4444
</v-dialog>
45-
<v-dialog
46-
v-model="SimulatorState.dialogBox.hex_bin_dec_converter_dialog"
47-
:persistent="false"
48-
>
49-
<v-card class="messageBoxContent">
50-
<v-card-text>
51-
<p class="dialogHeader">Hex-Bin-Dec Converter</p>
52-
<v-btn
53-
size="x-small"
54-
icon
55-
class="dialogClose"
56-
@click="
57-
SimulatorState.dialogBox.hex_bin_dec_converter_dialog = false
58-
"
59-
>
60-
<v-icon>mdi-close</v-icon>
61-
</v-btn>
62-
<div
63-
v-for="(value, index) in Object.entries(inputArr)"
64-
id="bitconverterprompt"
65-
:key="value[0]"
66-
title="Dec-Bin-Hex-Converter"
67-
>
68-
<label>{{ value[1].label }}</label>
69-
<br />
70-
<input
71-
:id="value[0]"
72-
type="text"
73-
:value="value[1].val"
74-
:label="value[1].label"
75-
name="text1"
76-
@keyup="(payload) => converter(payload)"
77-
/>
78-
<br /><br />
79-
</div>
80-
</v-card-text>
81-
<v-card-actions>
82-
<v-btn class="messageBtn" block @click="setBaseValues(0)">
83-
Reset
84-
</v-btn>
85-
</v-card-actions>
86-
</v-card>
87-
</v-dialog>
8845
</template>
8946

9047
<script lang="ts" setup>
@@ -124,10 +81,10 @@ function converter(e: KeyboardEvent) {
12481
let value = target.value
12582
12683
// Regular expressions for validating input
127-
const regexBinary = /[^01]/g
84+
const regexBinary = /[^01b]/g
12885
const regexOctal = /[^0-7]/g
12986
const regexDecimal = /[^0-9]/g
130-
const regexHex = /[^0-9A-Fa-f]/g
87+
const regexHex = /[^0-9A-Fa-fx]/g
13188
13289
switch (target.id) {
13390
case 'decimalInput':
@@ -213,7 +170,12 @@ function octalConverter(input: string) {
213170
}
214171
215172
function hexConverter(input: string) {
216-
let x = parseInt(input, 16)
173+
let x
174+
if (input.slice(0, 2) == '0x' || input.slice(0, 2) == '0X') {
175+
x = parseInt(input.slice(2), 16)
176+
} else {
177+
x = parseInt(input, 16)
178+
}
217179
setBaseValues(x)
218180
}
219181
</script>

0 commit comments

Comments
 (0)