Notification post:// get:// etc - Fixing URL encoding of headers so that '+' in URL is correctly parsed as ' ' (and other url-encodings) (#2745)

2747-dont-check-paused-on-edit
dgtlmoon 3 weeks ago committed by GitHub
parent e8b82c47ca
commit 563c196396
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -13,6 +13,7 @@ from loguru import logger
def apprise_custom_api_call_wrapper(body, title, notify_type, *args, **kwargs): def apprise_custom_api_call_wrapper(body, title, notify_type, *args, **kwargs):
import requests import requests
import json import json
from urllib.parse import unquote_plus
from apprise.utils import parse_url as apprise_parse_url from apprise.utils import parse_url as apprise_parse_url
from apprise import URLBase from apprise import URLBase
@ -47,7 +48,7 @@ def apprise_custom_api_call_wrapper(body, title, notify_type, *args, **kwargs):
if results: if results:
# Add our headers that the user can potentially over-ride if they wish # Add our headers that the user can potentially over-ride if they wish
# to to our returned result set and tidy entries by unquoting them # to to our returned result set and tidy entries by unquoting them
headers = {URLBase.unquote(x): URLBase.unquote(y) headers = {unquote_plus(x): unquote_plus(y)
for x, y in results['qsd+'].items()} for x, y in results['qsd+'].items()}
# https://github.com/caronc/apprise/wiki/Notify_Custom_JSON#get-parameter-manipulation # https://github.com/caronc/apprise/wiki/Notify_Custom_JSON#get-parameter-manipulation
@ -55,14 +56,14 @@ def apprise_custom_api_call_wrapper(body, title, notify_type, *args, **kwargs):
# but here we are making straight requests, so we need todo convert this against apprise's logic # but here we are making straight requests, so we need todo convert this against apprise's logic
for k, v in results['qsd'].items(): for k, v in results['qsd'].items():
if not k.strip('+-') in results['qsd+'].keys(): if not k.strip('+-') in results['qsd+'].keys():
params[URLBase.unquote(k)] = URLBase.unquote(v) params[unquote_plus(k)] = unquote_plus(v)
# Determine Authentication # Determine Authentication
auth = '' auth = ''
if results.get('user') and results.get('password'): if results.get('user') and results.get('password'):
auth = (URLBase.unquote(results.get('user')), URLBase.unquote(results.get('user'))) auth = (unquote_plus(results.get('user')), unquote_plus(results.get('user')))
elif results.get('user'): elif results.get('user'):
auth = (URLBase.unquote(results.get('user'))) auth = (unquote_plus(results.get('user')))
# Try to auto-guess if it's JSON # Try to auto-guess if it's JSON
h = 'application/json; charset=utf-8' h = 'application/json; charset=utf-8'

@ -284,7 +284,7 @@ def test_notification_custom_endpoint_and_jinja2(client, live_server, measure_me
# CUSTOM JSON BODY CHECK for POST:// # CUSTOM JSON BODY CHECK for POST://
set_original_response() set_original_response()
# https://github.com/caronc/apprise/wiki/Notify_Custom_JSON#header-manipulation # https://github.com/caronc/apprise/wiki/Notify_Custom_JSON#header-manipulation
test_notification_url = url_for('test_notification_endpoint', _external=True).replace('http://', 'post://')+"?xxx={{ watch_url }}&+custom-header=123" 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"
res = client.post( res = client.post(
url_for("settings_page"), url_for("settings_page"),
@ -326,6 +326,7 @@ def test_notification_custom_endpoint_and_jinja2(client, live_server, measure_me
assert j['secret'] == 444 assert j['secret'] == 444
assert j['somebug'] == '网站监测 内容更新了' assert j['somebug'] == '网站监测 内容更新了'
# URL check, this will always be converted to lowercase # URL check, this will always be converted to lowercase
assert os.path.isfile("test-datastore/notification-url.txt") assert os.path.isfile("test-datastore/notification-url.txt")
with open("test-datastore/notification-url.txt", 'r') as f: 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
with open("test-datastore/notification-headers.txt", 'r') as f: with open("test-datastore/notification-headers.txt", 'r') as f:
notification_headers = f.read() notification_headers = f.read()
assert 'custom-header: 123' in notification_headers.lower() assert 'custom-header: 123' in notification_headers.lower()
assert 'second: hello world "space"' in notification_headers.lower()
# Should always be automatically detected as JSON content type even when we set it as 'Text' (default) # Should always be automatically detected as JSON content type even when we set it as 'Text' (default)

Loading…
Cancel
Save