From 2e69774b1ffd78e558b5c61b3191b188cee5927d Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Mon, 30 Jul 2018 08:30:08 -0500 Subject: [PATCH] Fix video ID redirect --- src/invidious.cr | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index fa7c0b21..b0df9dc0 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -378,7 +378,7 @@ get "/watch" do |env| scheme = "https://" else scheme = "http://" - end + end host = env.request.headers["Host"] url = "#{scheme}#{host}" @@ -2615,18 +2615,22 @@ end get "/:id" do |env| id = env.params.url["id"] - params = [] of String - env.params.query.each do |k, v| - params << "#{k}=#{v}" - end - params = params.join("&") + if md = id.match(/[a-zA-Z0-9_-]{11}/) + params = [] of String + env.params.query.each do |k, v| + params << "#{k}=#{v}" + end + params = params.join("&") - url = "/watch?v=#{id}" - if params - url += "&#{params}" - end + url = "/watch?v=#{id}" + if params + url += "&#{params}" + end - env.redirect url + env.redirect url + else + env.response.status_code = 404 + end end error 404 do |env|