From 9e49ee24fb570746dbeae23833c74d82e38ccdcb Mon Sep 17 00:00:00 2001 From: Sam Davies Date: Wed, 5 Apr 2017 14:42:56 +0100 Subject: [PATCH] Do not mutate strings passed as config options, fixes #461 --- app/controllers/apipie/apipies_controller.rb | 10 +++++++--- spec/dummy/config/initializers/apipie.rb | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/apipie/apipies_controller.rb b/app/controllers/apipie/apipies_controller.rb index 34b775eb..cbf2132a 100644 --- a/app/controllers/apipie/apipies_controller.rb +++ b/app/controllers/apipie/apipies_controller.rb @@ -114,9 +114,13 @@ def authorized_doc def get_format [:resource, :method, :version].each do |par| - if params[par] - params[:format] = :html unless params[par].sub!('.html', '').nil? - params[:format] = :json unless params[par].sub!('.json', '').nil? + next unless params[par] + [:html, :json].each do |format| + extension = ".#{format}" + if params[par].include?(extension) + params[par] = params[par].sub(extension, '') + params[:format] = format + end end end request.format = params[:format] if params[:format] diff --git a/spec/dummy/config/initializers/apipie.rb b/spec/dummy/config/initializers/apipie.rb index a2546bcc..763a3f81 100644 --- a/spec/dummy/config/initializers/apipie.rb +++ b/spec/dummy/config/initializers/apipie.rb @@ -6,7 +6,7 @@ # can be overriden in resource_description # by default is it 1.0 if not specified anywhere # this must be defined before api_base_url and app_info - config.default_version = "development" + config.default_version = "development".freeze config.doc_base_url = "/apidoc"