File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,9 +106,15 @@ def parse_input_headers(infiles):
106106
107107def make_bytes (cfg_bytes_len , cfg_bytes_hash , qstr ):
108108 qhash = compute_hash (qstr , cfg_bytes_hash )
109- # Calculate len of str, taking escapes into account
110- qlen = len (qstr .replace ("\\ \\ " , "-" ).replace ("\\ " , "" ))
111- qdata = qstr .replace ('"' , '\\ "' )
109+ if all (32 <= ord (c ) <= 126 and c != '\\ ' for c in qstr ):
110+ # qstr is all printable ASCII so render it as-is (for easier debugging)
111+ qlen = len (qstr )
112+ qdata = qstr
113+ else :
114+ # qstr contains non-printable codes so render entire thing as hex pairs
115+ qbytes = qstr .encode ('utf8' )
116+ qlen = len (qbytes )
117+ qdata = '' .join (('\\ x%02x' % b ) for b in qbytes )
112118 if qlen >= (1 << (8 * cfg_bytes_len )):
113119 print ('qstr is too long:' , qstr )
114120 assert False
You can’t perform that action at this time.
0 commit comments