File tree 3 files changed +17
-4
lines changed
3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -49,23 +49,23 @@ def validate_expression(param):
49
49
for token in split_tokens (param ):
50
50
state = 0
51
51
for c in token :
52
- if c not in ' \t +-*/%()<>&|~x0123456789abcdef ' :
52
+ if c not in ' \t +-*/%()<>&|~xX0123456789abcdefABCDEF ' :
53
53
return False
54
54
55
55
# the following allows hex digits a-f after 0x but not otherwise
56
56
if state == 0 :
57
- if c in 'abcdef ' :
57
+ if c in 'abcdefABCDEF ' :
58
58
return False
59
59
if c == '0' :
60
60
state = 1
61
61
continue
62
62
63
63
if state == 1 :
64
- state = 2 if c == 'x ' else 0
64
+ state = 2 if c in 'xX ' else 0
65
65
continue
66
66
67
67
if state == 2 :
68
- if c not in '0123456789abcdef ' :
68
+ if c not in '0123456789abcdefABCDEF ' :
69
69
state = 0
70
70
return True
71
71
Original file line number Diff line number Diff line change 46
46
move r3, 0x1234 & ~2
47
47
move r3, 42|4&0xf # 46 (4&0xf is evaluated first)
48
48
move r3, (42|4 )&0xf # 14 (42|4 is evaluated first)
49
+
50
+ # ---
51
+ # test that expressions accept hex characters in either upper or lower case
52
+ move r3, 0xaa - 1
53
+ move r3, 0xBB - 1
54
+ move r3, 0xCc - 1
55
+ move r3, 0Xdd - 1
56
+ move r3, 0XEF - 1
Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ def test_validate_expression():
44
44
assert validate_expression ('0x100 & ~2' ) is True
45
45
assert validate_expression ('0xabcdef' ) is True
46
46
assert validate_expression ('0x123def' ) is True
47
+ assert validate_expression ('0xABC' ) is True
48
+ assert validate_expression ('0xaBc' ) is True
49
+ assert validate_expression ('0Xabc' ) is True
50
+ assert validate_expression ('0X123ABC' ) is True
47
51
assert validate_expression ('2*3+4/5&6|7' ) is True
48
52
assert validate_expression ('(((((1+1) * 2' ) is True # valid characters, even if expression is not valid
49
53
@@ -55,6 +59,7 @@ def test_validate_expression():
55
59
assert validate_expression ('123 ^ 4' ) is False # operator not supported for now
56
60
assert validate_expression ('evil()' ) is False
57
61
assert validate_expression ('def cafe()' ) is False # valid hex digits, but potentially dangerous code
62
+ assert validate_expression ('def CAFE()' ) is False
58
63
59
64
60
65
@test
You can’t perform that action at this time.
0 commit comments