Skip to content

Commit

Permalink
fix: is hex checks if a strings begin with 0x
Browse files Browse the repository at this point in the history
  • Loading branch information
albertolerda authored and jaromil committed Jul 4, 2023
1 parent 3c8df4b commit 472d66f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/zen_octet.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ int is_base58(lua_State *L, const char *in) {
int is_hex(lua_State *L, const char *in) {
(void)L;
if(!in) { ERROR(); return 0; }
if ( (in[0] == '0') && (in[1] == 'x') ) {
in+=2;
}
int c;
for(c=0; in[c]!=0; c++) {
if (!isxdigit(in[c])) {
Expand Down
19 changes: 19 additions & 0 deletions test/zencode/given.bats
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,22 @@ EOF
run $ZENROOM_EXECUTABLE -z -a given_in_path.data given_in_path_fail_not_a_table.zen
assert_line '[W] [!] Object is not a table: my_hex'
}

@test "Read hex with 0x prefix" {
cat << eof | save_asset hex_0x_prefix.data
{
"0xprefix": "0x7d6df85bDBCe99151c813fd1DDE6BC007c523C27"
}
eof
cat <<EOF | zexe hex_0x_prefix.zen hex_0x_prefix.data
Scenario ethereum
Given I have a 'hex' named '0xprefix'
Given I rename '0xprefix' to 'myhex'
Given I have a 'ethereum address' named '0xprefix'
Then print data
EOF
save_output "hex_0x_prefix.out"
assert_output '{"0xprefix":"0x7d6df85bDBCe99151c813fd1DDE6BC007c523C27","myhex":"7d6df85bdbce99151c813fd1dde6bc007c523c27"}'
}

0 comments on commit 472d66f

Please sign in to comment.