The little things give you away... A collection of various small helper stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 lines
1.5 KiB

  1. #!/usr/bin/python3
  2. import io
  3. import itertools
  4. import subprocess
  5. def test(input, output):
  6. p = subprocess.Popen(['./.make-and-exec-binaries/urldecode'], text = False, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
  7. stdout, stderr = p.communicate(input)
  8. assert not stderr
  9. if stdout != output:
  10. for i in range(0, len(stdout), 3):
  11. print(repr(stdout[i : i+3]))
  12. for i in range(0, len(output), 3):
  13. print(repr(output[i : i+3]))
  14. assert stdout == output
  15. BUFFER_SIZE = 1024 * 300
  16. test(b'', b'')
  17. test(b'a', b'a')
  18. test(b'%', b'%')
  19. test(b'%2', b'%2')
  20. test(b'%20', b' ')
  21. test(b'%gg', b'%gg')
  22. #test(b'%\xc3\xa4', b'%\xc3\xa4')
  23. for i in range(256):
  24. test(f'%{i:02X}'.encode('ascii'), bytes.fromhex(f'{i:02x}'))
  25. test(f'%{i:02x}'.encode('ascii'), bytes.fromhex(f'{i:02x}'))
  26. hexbytes = tuple(f'{i:02x}' for i in range(256)) # ('00', '01', .., 'ff')
  27. data = bytes.fromhex(''.join(map(''.join, filter(lambda x: any(c < '30' or '39' < c < '41' or '46' < c < '61' or '66' < c for c in x[1:]), itertools.product(('25',), hexbytes, hexbytes)))))
  28. test(data, data)
  29. for offset in range(-3, 1):
  30. test(b'a' * (BUFFER_SIZE + offset) + b'%25', b'a' * (BUFFER_SIZE + offset) + b'%')
  31. test(b'a' * (BUFFER_SIZE + offset) + b'%gg', b'a' * (BUFFER_SIZE + offset) + b'%gg')
  32. test(b'a' * (BUFFER_SIZE + offset) + b'%', b'a' * (BUFFER_SIZE + offset) + b'%')
  33. test(b'a' * (BUFFER_SIZE + offset) + b'%2', b'a' * (BUFFER_SIZE + offset) + b'%2')
  34. test(b'a' * (BUFFER_SIZE + offset) + b'%g', b'a' * (BUFFER_SIZE + offset) + b'%g')
  35. for i in range(10):
  36. test(b'%' * i + b'%20', b'%' * i + b' ')