Skip to content

Commit

Permalink
Partially restore URI.escape behaviour to avoid breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
littldr committed Dec 27, 2017
1 parent f21b20e commit 985c214
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/route_translator/translator/path/segment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def translate_string(str, locale, scope)
sanitized_locale = RouteTranslator::LocaleSanitizer.sanitize(locale)
translated_resource = translate_resource(str, sanitized_locale, scope)

CGI.escape translated_resource
# restore URI.escape behaviour to avoid breaking change
CGI.escape(translated_resource).gsub('%2F', '/')
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/dummy/app/controllers/dummy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ def engine_es
def engine
render plain: blorgh.posts_path
end

def slash
render plain: request.env['PATH_INFO']
end
end
1 change: 1 addition & 0 deletions test/dummy/config/locales/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ es:
dummy: dummy
show: mostrar
suffix: sufijo
slash: foo/bar
ru:
routes:
dummy: манекен
Expand Down
1 change: 1 addition & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
localized do
get 'dummy', to: 'dummy#dummy'
get 'show', to: 'dummy#show'
get 'slash', to: 'dummy#slash'

get 'optional(/:page)', to: 'dummy#optional', as: :optional
get 'prefixed_optional(/p-:page)', to: 'dummy#prefixed_optional', as: :prefixed_optional
Expand Down
6 changes: 6 additions & 0 deletions test/integration/generated_path_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@ def test_path_translated_with_suffix
assert_response :success
assert_equal '10', response.body
end

def test_path_with_slash_in_translation
get '/es/foo/bar'
assert_response :success
assert_equal '/es/foo/bar', response.body
end
end
1 change: 1 addition & 0 deletions test/locales/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ es:
tr_param: tr_parametro
favourites: favoritos
blank: ""
slash: foo/bar
controllers:
people:
products:
Expand Down
10 changes: 10 additions & 0 deletions test/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ def test_params
assert_routing '/es/productos/product_slug', controller: 'products', action: 'show', locale: 'es', id: 'product_slug'
end

def test_slash_in_translation
draw_routes do
localized do
get 'slash', to: 'products#index'
end
end

assert_routing '/es/foo/bar', controller: 'products', action: 'index', locale: 'es'
end

def test_optional_segments
draw_routes do
localized do
Expand Down

0 comments on commit 985c214

Please sign in to comment.