The little things give you away... A collection of various small helper stuff
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

38 lignes
1.4 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. assert stdout == output
  10. BUFFER_SIZE = 1024 * 300
  11. test(b'', b'')
  12. test(b'a', b'a')
  13. test(b'%', b'%')
  14. test(b'%2', b'%2')
  15. test(b'%20', b' ')
  16. test(b'%gg', b'%gg')
  17. #test(b'%\xc3\xa4', b'%\xc3\xa4')
  18. for i in range(256):
  19. test(f'%{i:02X}'.encode('ascii'), bytes.fromhex(f'{i:02x}'))
  20. test(f'%{i:02x}'.encode('ascii'), bytes.fromhex(f'{i:02x}'))
  21. hexbytes = tuple(f'{i:02x}' for i in range(256)) # ('00', '01', .., 'ff')
  22. 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)))))
  23. test(data, data)
  24. for offset in range(-3, 1):
  25. test(b'a' * (BUFFER_SIZE + offset) + b'%25', b'a' * (BUFFER_SIZE + offset) + b'%')
  26. test(b'a' * (BUFFER_SIZE + offset) + b'%gg', b'a' * (BUFFER_SIZE + offset) + b'%gg')
  27. test(b'a' * (BUFFER_SIZE + offset) + b'%', b'a' * (BUFFER_SIZE + offset) + b'%')
  28. test(b'a' * (BUFFER_SIZE + offset) + b'%2', b'a' * (BUFFER_SIZE + offset) + b'%2')
  29. test(b'a' * (BUFFER_SIZE + offset) + b'%g', b'a' * (BUFFER_SIZE + offset) + b'%g')
  30. for i in range(10):
  31. test(b'%' * i + b'%20', b'%' * i + b' ')