mirror of
https://git.collinwebdesigns.de/oscar.krause/fastapi-dls.git
synced 2024-11-23 15:31:00 +03:00
code styling
This commit is contained in:
parent
15f14cac11
commit
fb3ac4291f
@ -11,6 +11,8 @@ logger = logging.getLogger(__name__)
|
|||||||
class PatchMalformedJsonMiddleware(BaseHTTPMiddleware):
|
class PatchMalformedJsonMiddleware(BaseHTTPMiddleware):
|
||||||
# see oscar.krause/fastapi-dls#1
|
# see oscar.krause/fastapi-dls#1
|
||||||
|
|
||||||
|
REGEX = '(\"mac_address_list\"\:\s?\[)([\w\d])'
|
||||||
|
|
||||||
def __init__(self, app, enabled: bool):
|
def __init__(self, app, enabled: bool):
|
||||||
super().__init__(app)
|
super().__init__(app)
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
@ -28,8 +30,7 @@ class PatchMalformedJsonMiddleware(BaseHTTPMiddleware):
|
|||||||
body = body.replace('\t', '')
|
body = body.replace('\t', '')
|
||||||
body = body.replace('\n', '')
|
body = body.replace('\n', '')
|
||||||
|
|
||||||
regex = '(\"mac_address_list\"\:\s?\[)([\w\d])'
|
s = re.sub(PatchMalformedJsonMiddleware.REGEX, r'\1"\2', body)
|
||||||
s = re.sub(regex, r'\1"\2', body)
|
|
||||||
logger.debug(f'Fixed JSON: "{s}"')
|
logger.debug(f'Fixed JSON: "{s}"')
|
||||||
s = json.loads(s) # ensure json is now valid
|
s = json.loads(s) # ensure json is now valid
|
||||||
|
|
||||||
|
@ -111,11 +111,11 @@ def test_auth_v1_origin():
|
|||||||
|
|
||||||
def test_auth_v1_origin_malformed_json(): # see oscar.krause/fastapi-dls#1
|
def test_auth_v1_origin_malformed_json(): # see oscar.krause/fastapi-dls#1
|
||||||
import re
|
import re
|
||||||
|
from middleware import PatchMalformedJsonMiddleware
|
||||||
|
|
||||||
# test regex (temporary, until this section is merged into main.py
|
# test regex (temporary, until this section is merged into main.py
|
||||||
json_test = '{"environment": {"fingerprint": {"mac_address_list": [ff:ff:ff:ff:ff:ff"]}}'
|
body = '{"environment": {"fingerprint": {"mac_address_list": [ff:ff:ff:ff:ff:ff"]}}'
|
||||||
regex = '(\"mac_address_list\"\:\s?\[)([\w\d])'
|
replaced = re.sub(PatchMalformedJsonMiddleware.REGEX, r'\1"\2', body)
|
||||||
replaced = re.sub(regex, r'\1"\2', json_test)
|
|
||||||
assert replaced == '{"environment": {"fingerprint": {"mac_address_list": ["ff:ff:ff:ff:ff:ff"]}}'
|
assert replaced == '{"environment": {"fingerprint": {"mac_address_list": ["ff:ff:ff:ff:ff:ff"]}}'
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user