From 352e409a6e5df40bb62b00e4053c4294390dd5a3 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Tue, 4 Jun 2019 19:58:56 -0500 Subject: [PATCH] Fix toggle_theme when visiting preferences with JS disabled --- src/invidious.cr | 2 +- src/invidious/helpers/utils.cr | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 24dcaf7e..e8621b23 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1487,7 +1487,7 @@ end get "/toggle_theme" do |env| locale = LOCALES[env.get("preferences").as(Preferences).locale]? - referer = get_referer(env) + referer = get_referer(env, unroll: false) redirect = env.params.query["redirect"]? redirect ||= "true" diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 9bdb6a7e..fcccb7f9 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -243,7 +243,7 @@ def make_host_url(config, kemal_config) return "#{scheme}#{host}#{port}" end -def get_referer(env, fallback = "/") +def get_referer(env, fallback = "/", unroll = true) referer = env.params.query["referer"]? referer ||= env.request.headers["referer"]? referer ||= fallback @@ -251,16 +251,18 @@ def get_referer(env, fallback = "/") referer = URI.parse(referer) # "Unroll" nested referrers - loop do - if referer.query - params = HTTP::Params.parse(referer.query.not_nil!) - if params["referer"]? - referer = URI.parse(URI.unescape(params["referer"])) + if unroll + loop do + if referer.query + params = HTTP::Params.parse(referer.query.not_nil!) + if params["referer"]? + referer = URI.parse(URI.unescape(params["referer"])) + else + break + end else break end - else - break end end