From 3dd4debf243c220b3fd6285815270f0ef8452bd4 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 10 Jul 2022 20:04:54 +0100 Subject: [PATCH] Add unit test for Lynx browser POST --- content.py | 4 ++++ tests.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/content.py b/content.py index 332726812..9caccaf87 100644 --- a/content.py +++ b/content.py @@ -1497,6 +1497,7 @@ def extract_text_fields_in_post(post_bytes, boundary: str, debug: bool, ) if debug: print('DEBUG: POST message_fields: ' + str(message_fields)) + lynx_content_type = 'Content-Type: text/plain; charset=utf-8' # examine each section of the POST, separated by the boundary for fld in message_fields: if fld == '--': @@ -1508,6 +1509,9 @@ def extract_text_fields_in_post(post_bytes, boundary: str, debug: bool, continue post_key = post_str.split('"', 1)[0] post_value_str = post_str.split('"', 1)[1] + if boundary == '--LYNX': + post_value_str = \ + post_value_str.replace(lynx_content_type, '') if ';' in post_value_str: if post_key not in fields_with_semicolon_allowed and \ not post_key.startswith('edited'): diff --git a/tests.py b/tests.py index 6bbe9e32d..7e2524463 100644 --- a/tests.py +++ b/tests.py @@ -5852,6 +5852,18 @@ def _test_extract_text_fields_from_post(): assert fields['imageDescription'] == '' assert fields['message'] == 'This is a ; test' + boundary = '--LYNX' + form_data = '--LYNX\r\nContent-Disposition: form-data; ' + \ + 'name="fieldName"\r\nContent-Type: text/plain; ' + \ + 'charset=utf-8\r\nThis is a lynx test\r\n--LYNX\r\n' + \ + 'Content-Disposition: form-data; name="submitYes"\r\n' + \ + 'Content-Type: text/plain; charset=utf-8\r\nBUTTON\r\n--LYNX--\r\n' + debug = True + fields = extract_text_fields_in_post(None, boundary, debug, form_data) + print('fields: ' + str(fields)) + assert fields['fieldName'] == 'This is a lynx test' + assert fields['submitYes'] == 'BUTTON' + def _test_speaker_replace_link(): print('testSpeakerReplaceLinks')