From 45f3e012dbbef2ece64eac5367edef794427f787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillem=20Nieto=20Tal=C3=B3?= Date: Mon, 20 May 2024 11:57:24 +0200 Subject: [PATCH] fix: urlencode since opaque string Since/next batch is an opaque string and might need to be urlencoded before being sent to the server. Signed-off-by: Guillem Nieto --- sync2/client.go | 2 +- sync2/client_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sync2/client.go b/sync2/client.go index 7d47f611..75d42e2d 100644 --- a/sync2/client.go +++ b/sync2/client.go @@ -152,7 +152,7 @@ func (v *HTTPClient) createSyncURL(since string, isFirst, toDeviceOnly bool) str qps += "timeout=30000" } if since != "" { - qps += "&since=" + since + qps += "&since=" + url.QueryEscape(since) } // Set presence to offline, this potentially reduces CPU load on upstream homeservers diff --git a/sync2/client_test.go b/sync2/client_test.go index f8d82d09..ae6fbcec 100644 --- a/sync2/client_test.go +++ b/sync2/client_test.go @@ -65,6 +65,12 @@ func TestSyncURL(t *testing.T) { toDeviceOnly: true, wantURL: wantBaseURL + `?timeout=0&since=112233&set_presence=offline&filter=` + url.QueryEscape(`{"presence":{"not_types":["*"]},"room":{"rooms":[],"timeline":{"limit":50}}}`), }, + { + since: "112233#145", + isFirst: true, + toDeviceOnly: true, + wantURL: wantBaseURL + `?timeout=0&since=112233%23145&set_presence=offline&filter=` + url.QueryEscape(`{"presence":{"not_types":["*"]},"room":{"rooms":[],"timeline":{"limit":50}}}`), + }, } for i, tc := range testCases { gotURL := client.createSyncURL(tc.since, tc.isFirst, tc.toDeviceOnly)