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.
 
 
 

39 lines
1.4 KiB

  1. #!/usr/bin/python3
  2. import io
  3. import itertools
  4. import os.path
  5. import subprocess
  6. def test(input, output):
  7. p = subprocess.Popen([os.path.join(os.path.dirname(__file__), '.make-and-exec-binaries', 'urldecode')], text = False, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
  8. stdout, stderr = p.communicate(input)
  9. assert not stderr
  10. assert stdout == output
  11. BUFFER_SIZE = 1024 * 300
  12. test(b'', b'')
  13. test(b'a', b'a')
  14. test(b'%', b'%')
  15. test(b'%2', b'%2')
  16. test(b'%20', b' ')
  17. test(b'%gg', b'%gg')
  18. #test(b'%\xc3\xa4', b'%\xc3\xa4')
  19. for i in range(256):
  20. test(f'%{i:02X}'.encode('ascii'), bytes.fromhex(f'{i:02x}'))
  21. test(f'%{i:02x}'.encode('ascii'), bytes.fromhex(f'{i:02x}'))
  22. hexbytes = tuple(f'{i:02x}' for i in range(256)) # ('00', '01', .., 'ff')
  23. 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)))))
  24. test(data, data)
  25. for offset in range(-3, 1):
  26. test(b'a' * (BUFFER_SIZE + offset) + b'%25', b'a' * (BUFFER_SIZE + offset) + b'%')
  27. test(b'a' * (BUFFER_SIZE + offset) + b'%gg', b'a' * (BUFFER_SIZE + offset) + b'%gg')
  28. test(b'a' * (BUFFER_SIZE + offset) + b'%', b'a' * (BUFFER_SIZE + offset) + b'%')
  29. test(b'a' * (BUFFER_SIZE + offset) + b'%2', b'a' * (BUFFER_SIZE + offset) + b'%2')
  30. test(b'a' * (BUFFER_SIZE + offset) + b'%g', b'a' * (BUFFER_SIZE + offset) + b'%g')
  31. for i in range(10):
  32. test(b'%' * i + b'%20', b'%' * i + b' ')