Skip to content

Commit

Permalink
Header handling - Fix header parsing to split on the first colon only…
Browse files Browse the repository at this point in the history
… (headers where the value contained :// type may have been broken) (#2929)
  • Loading branch information
iafuad authored Jan 25, 2025
1 parent e799a1c commit 1c61b5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion changedetectionio/model/App.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 6 additions & 3 deletions changedetectionio/tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'):
Expand Down

0 comments on commit 1c61b5a

Please sign in to comment.