Skip to content

Commit 698a7e1

Browse files
committed
Fix string test
1 parent b5d2e1b commit 698a7e1

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

tests/test_strings.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# pylint: disable=missing-class-docstring,no-self-use
22
from __future__ import annotations
33

4+
import re
45
import unittest
56

67
import claripy
@@ -12,6 +13,19 @@ class TestStrings(unittest.TestCase):
1213
def get_solver(self):
1314
return claripy.SolverStrings(backend=claripy.backends.z3)
1415

16+
def replace_unicode(self, match):
17+
"""
18+
Converts a Unicode escape sequence to the corresponding character.
19+
20+
Args:
21+
- match (re.Match): A regex match object containing a Unicode escape sequence.
22+
23+
Returns:
24+
- str: The Unicode character corresponding to the hexadecimal code.
25+
"""
26+
hex_code = match.group(1)
27+
return chr(int(hex_code, 16))
28+
1529
def test_concat(self):
1630
str_concrete = claripy.StringV("conc")
1731
str_symbol = claripy.StringS("symb_concat", 4, explicit_name=True)
@@ -268,7 +282,6 @@ def test_index_of_simplification(self):
268282
self.assertEqual((), tuple(solver.constraints))
269283
self.assertEqual((target_idx,), solver.eval(res, 2))
270284

271-
@unittest.skip("Usually hangs")
272285
def test_index_of_symbolic_start_idx(self):
273286
str_symb = claripy.StringS("symb_index_of", 4, explicit_name=True)
274287
start_idx = claripy.BVS("symb_start_idx", 32, explicit_name=True)
@@ -281,12 +294,14 @@ def test_index_of_symbolic_start_idx(self):
281294

282295
solver.add(res != -1)
283296
solver.add(res < 38)
297+
284298
self.assertTrue(solver.satisfiable())
285-
self.assertEqual({33, 34, 35, 36, 37}, set(solver.eval(res, 10)))
299+
self.assertEqual({33, 34, 35, 36, 37}, set(solver.eval(res, 5)))
286300

287301
strs = solver.eval(str_symb, 10 if KEEP_TEST_PERFORMANT else 100)
288302
for s in strs:
289-
self.assertTrue(32 < s.index("an") < 38)
303+
converted_string = re.sub(r"\\u\{([0-9a-fA-F]+)\}", self.replace_unicode, s)
304+
self.assertTrue(32 < converted_string.index("an") < 38)
290305

291306
def test_str_to_int(self):
292307
str_symb = claripy.StringS("symb_strtoint", 4, explicit_name=True)

0 commit comments

Comments
 (0)