Skip to content

Commit 563c196

Browse files
authored
Notification post:// get:// etc - Fixing URL encoding of headers so that '+' in URL is correctly parsed as ' ' (and other url-encodings) (#2745)
1 parent e8b82c4 commit 563c196

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

changedetectionio/apprise_plugin/__init__.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
def apprise_custom_api_call_wrapper(body, title, notify_type, *args, **kwargs):
1414
import requests
1515
import json
16+
from urllib.parse import unquote_plus
1617
from apprise.utils import parse_url as apprise_parse_url
1718
from apprise import URLBase
1819

@@ -47,22 +48,22 @@ def apprise_custom_api_call_wrapper(body, title, notify_type, *args, **kwargs):
4748
if results:
4849
# Add our headers that the user can potentially over-ride if they wish
4950
# to to our returned result set and tidy entries by unquoting them
50-
headers = {URLBase.unquote(x): URLBase.unquote(y)
51+
headers = {unquote_plus(x): unquote_plus(y)
5152
for x, y in results['qsd+'].items()}
5253

5354
# https://github.com/caronc/apprise/wiki/Notify_Custom_JSON#get-parameter-manipulation
5455
# In Apprise, it relies on prefixing each request arg with "-", because it uses say &method=update as a flag for apprise
5556
# but here we are making straight requests, so we need todo convert this against apprise's logic
5657
for k, v in results['qsd'].items():
5758
if not k.strip('+-') in results['qsd+'].keys():
58-
params[URLBase.unquote(k)] = URLBase.unquote(v)
59+
params[unquote_plus(k)] = unquote_plus(v)
5960

6061
# Determine Authentication
6162
auth = ''
6263
if results.get('user') and results.get('password'):
63-
auth = (URLBase.unquote(results.get('user')), URLBase.unquote(results.get('user')))
64+
auth = (unquote_plus(results.get('user')), unquote_plus(results.get('user')))
6465
elif results.get('user'):
65-
auth = (URLBase.unquote(results.get('user')))
66+
auth = (unquote_plus(results.get('user')))
6667

6768
# Try to auto-guess if it's JSON
6869
h = 'application/json; charset=utf-8'

changedetectionio/tests/test_notification.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def test_notification_custom_endpoint_and_jinja2(client, live_server, measure_me
284284
# CUSTOM JSON BODY CHECK for POST://
285285
set_original_response()
286286
# https://github.com/caronc/apprise/wiki/Notify_Custom_JSON#header-manipulation
287-
test_notification_url = url_for('test_notification_endpoint', _external=True).replace('http://', 'post://')+"?xxx={{ watch_url }}&+custom-header=123"
287+
test_notification_url = url_for('test_notification_endpoint', _external=True).replace('http://', 'post://')+"?xxx={{ watch_url }}&+custom-header=123&+second=hello+world%20%22space%22"
288288

289289
res = client.post(
290290
url_for("settings_page"),
@@ -326,6 +326,7 @@ def test_notification_custom_endpoint_and_jinja2(client, live_server, measure_me
326326
assert j['secret'] == 444
327327
assert j['somebug'] == '网站监测 内容更新了'
328328

329+
329330
# URL check, this will always be converted to lowercase
330331
assert os.path.isfile("test-datastore/notification-url.txt")
331332
with open("test-datastore/notification-url.txt", 'r') as f:
@@ -337,6 +338,7 @@ def test_notification_custom_endpoint_and_jinja2(client, live_server, measure_me
337338
with open("test-datastore/notification-headers.txt", 'r') as f:
338339
notification_headers = f.read()
339340
assert 'custom-header: 123' in notification_headers.lower()
341+
assert 'second: hello world "space"' in notification_headers.lower()
340342

341343

342344
# Should always be automatically detected as JSON content type even when we set it as 'Text' (default)

0 commit comments

Comments
 (0)