add support for base64 encoding with the data scheme
This commit is contained in:
parent
5f4826cc73
commit
9e0192fe52
@ -1,3 +1,4 @@
|
|||||||
|
import base64
|
||||||
import os.path
|
import os.path
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
@ -129,6 +130,8 @@ class Request:
|
|||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
def data_request(self):
|
def data_request(self):
|
||||||
|
if self.url.media_encoding == "base64":
|
||||||
|
return base64.b64decode(self.url.data)
|
||||||
return self.url.data
|
return self.url.data
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import base64
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from browser import URL
|
from browser import URL
|
||||||
@ -188,7 +190,7 @@ def test_url_parsing(url_string, scheme, host, port, path, query, fragment, pars
|
|||||||
True,
|
True,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"data:text/plain;base64,This is some text",
|
"data:text/plain;base64,VGhpcyBpcyBzb21lIHRleHQ=",
|
||||||
"text/plain",
|
"text/plain",
|
||||||
"base64",
|
"base64",
|
||||||
"This is some text",
|
"This is some text",
|
||||||
@ -200,7 +202,10 @@ def test_data_url_parsing(url_string, media_type, media_encoding, data, parse_su
|
|||||||
url, success = parse_url(url_string)
|
url, success = parse_url(url_string)
|
||||||
assert url.media_type == media_type
|
assert url.media_type == media_type
|
||||||
assert url.media_encoding == media_encoding
|
assert url.media_encoding == media_encoding
|
||||||
assert url.data == data
|
if media_encoding == "base64":
|
||||||
|
assert base64.b64decode(url.data).decode("utf8") == data;
|
||||||
|
else:
|
||||||
|
assert url.data == data
|
||||||
assert success == parse_success
|
assert success == parse_success
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user