Fix broken StoriesController#show article with bad chars (#6248) [deploy]

This commit is contained in:
Matej Minárik 2020-02-24 19:41:06 +01:00 committed by GitHub
parent 3e8e7fb093
commit e9a0efbbf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View file

@ -20,6 +20,10 @@ class ApplicationController < ActionController::Base
raise NotAuthorizedError, "Unauthorized"
end
def bad_request
render json: "Error: Bad Request", status: :bad_request
end
def authenticate_user!
return if current_user

View file

@ -14,6 +14,8 @@ class StoriesController < ApplicationController
before_action :authenticate_user!, except: %i[index search show]
before_action :set_cache_control_headers, only: %i[index search show]
rescue_from ArgumentError, with: :bad_request
def index
@page = (params[:page] || 1).to_i
@article_index = true

View file

@ -119,6 +119,13 @@ RSpec.describe "StoriesShow", type: :request do
get article.path
expect(response.body).not_to include('"canonical" href="' + article.canonical_url.to_s + '"')
end
it "handles invalid slug characters" do
allow(Article).to receive(:find_by).and_raise(ArgumentError)
get article.path
expect(response.status).to be(400)
end
end
describe "GET /:username (org)" do