Fix sending to a stream with a space in its name.

Previously if you tried to send to "a b", we actually ended up trying
to send to "a%20b", since we were url-encoding the stream name and
then not properly decoding it.

(imported from commit 307d2999bd309e47fc654ae4422ab4372edde064)
This commit is contained in:
Tim Abbott
2012-10-17 14:05:17 -04:00
parent e6c1b2a4b7
commit 7237b4a73e
4 changed files with 8 additions and 4 deletions

View File

@@ -22,7 +22,7 @@ urlpatterns = patterns('',
url(r'^json/subscriptions/list$', 'zephyr.views.json_list_subscriptions', name='json_list_subscriptions'), url(r'^json/subscriptions/list$', 'zephyr.views.json_list_subscriptions', name='json_list_subscriptions'),
url(r'^json/subscriptions/remove$', 'zephyr.views.json_remove_subscription', name='json_remove_subscription'), url(r'^json/subscriptions/remove$', 'zephyr.views.json_remove_subscription', name='json_remove_subscription'),
url(r'^json/subscriptions/add$', 'zephyr.views.json_add_subscription', name='json_add_subscription'), url(r'^json/subscriptions/add$', 'zephyr.views.json_add_subscription', name='json_add_subscription'),
url(r'^json/subscriptions/exists/(?P<stream>.*)$', 'zephyr.views.json_stream_exists', name='json_stream_exists'), url(r'^json/subscriptions/exists$', 'zephyr.views.json_stream_exists', name='json_stream_exists'),
# These are json format views used by the API. They require an API key. # These are json format views used by the API. They require an API key.
url(r'^api/v1/get_messages$', 'zephyr.views.api_get_messages', name='api_get_messages'), url(r'^api/v1/get_messages$', 'zephyr.views.api_get_messages', name='api_get_messages'),

View File

@@ -102,7 +102,8 @@ function check_stream_for_send(stream_name) {
var okay = true; var okay = true;
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/json/subscriptions/exists/" + stream_name, url: "/json/subscriptions/exists",
data: {'stream': stream_name},
async: false, async: false,
success: function (data) { success: function (data) {
if (data.exists === "False") { if (data.exists === "False") {

View File

@@ -123,7 +123,7 @@ class PublicURLTest(TestCase):
"/json/settings/change/", "/json/settings/change/",
"/json/subscriptions/list", "/json/subscriptions/list",
"/json/subscriptions/remove", "/json/subscriptions/remove",
"/json/subscriptions/exists/test", "/json/subscriptions/exists",
"/json/subscriptions/add"], "/json/subscriptions/add"],
} }
for status_code, url_set in urls.iteritems(): for status_code, url_set in urls.iteritems():

View File

@@ -591,7 +591,10 @@ def json_change_settings(request):
return json_success(result) return json_success(result)
@login_required_json_view @login_required_json_view
def json_stream_exists(request, stream): def json_stream_exists(request):
if "stream" not in request.POST:
return json_error("Missing stream argument.")
stream = request.POST.get("stream")
if not valid_stream_name(stream): if not valid_stream_name(stream):
return json_error("Invalid characters in stream name") return json_error("Invalid characters in stream name")
exists = bool(get_stream(stream, UserProfile.objects.get(user=request.user).realm)) exists = bool(get_stream(stream, UserProfile.objects.get(user=request.user).realm))