From 1c61b5a6239c9e4632492b7950db282e1466f933 Mon Sep 17 00:00:00 2001 From: Iftekhar Alam Fuad Date: Sun, 26 Jan 2025 05:08:09 +0600 Subject: [PATCH] Header handling - Fix header parsing to split on the first colon only (headers where the value contained :// type may have been broken) (#2929) --- changedetectionio/model/App.py | 2 +- changedetectionio/tests/test_request.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/changedetectionio/model/App.py b/changedetectionio/model/App.py index b70a7ff0072..4c9c34fec05 100644 --- a/changedetectionio/model/App.py +++ b/changedetectionio/model/App.py @@ -69,7 +69,7 @@ def parse_headers_from_text_file(filepath): for l in f.readlines(): l = l.strip() if not l.startswith('#') and ':' in l: - (k, v) = l.split(':') + (k, v) = l.split(':', 1) # Split only on the first colon headers[k.strip()] = v.strip() return headers \ No newline at end of file diff --git a/changedetectionio/tests/test_request.py b/changedetectionio/tests/test_request.py index e3511f81aba..88816308f8e 100644 --- a/changedetectionio/tests/test_request.py +++ b/changedetectionio/tests/test_request.py @@ -373,13 +373,13 @@ def test_headers_textfile_in_request(client, live_server, measure_memory_usage): wait_for_all_checks(client) with open('test-datastore/headers-testtag.txt', 'w') as f: - f.write("tag-header: test") + f.write("tag-header: test\r\nurl-header: http://example.com") with open('test-datastore/headers.txt', 'w') as f: - f.write("global-header: nice\r\nnext-global-header: nice") + f.write("global-header: nice\r\nnext-global-header: nice\r\nurl-header-global: http://example.com/global") with open('test-datastore/' + extract_UUID_from_client(client) + '/headers.txt', 'w') as f: - f.write("watch-header: nice") + f.write("watch-header: nice\r\nurl-header-watch: http://example.com/watch") wait_for_all_checks(client) client.get(url_for("form_watch_checknow"), follow_redirects=True) @@ -410,6 +410,9 @@ def test_headers_textfile_in_request(client, live_server, measure_memory_usage): assert b"Xxx:ooo" in res.data assert b"Watch-Header:nice" in res.data assert b"Tag-Header:test" in res.data + assert b"Url-Header:http://example.com" in res.data + assert b"Url-Header-Global:http://example.com/global" in res.data + assert b"Url-Header-Watch:http://example.com/watch" in res.data # Check the custom UA from system settings page made it through if os.getenv('PLAYWRIGHT_DRIVER_URL'):