diff --git a/lib/route_translator/translator/path/segment.rb b/lib/route_translator/translator/path/segment.rb index 9c9b3eec..e740190a 100644 --- a/lib/route_translator/translator/path/segment.rb +++ b/lib/route_translator/translator/path/segment.rb @@ -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 diff --git a/test/dummy/app/controllers/dummy_controller.rb b/test/dummy/app/controllers/dummy_controller.rb index 5bd6ee06..99c6cff0 100644 --- a/test/dummy/app/controllers/dummy_controller.rb +++ b/test/dummy/app/controllers/dummy_controller.rb @@ -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 diff --git a/test/dummy/config/locales/all.yml b/test/dummy/config/locales/all.yml index bde14756..eb718a24 100644 --- a/test/dummy/config/locales/all.yml +++ b/test/dummy/config/locales/all.yml @@ -10,6 +10,7 @@ es: dummy: dummy show: mostrar suffix: sufijo + slash: foo/bar ru: routes: dummy: манекен diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index 35a340ab..ca4bbd46 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -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 diff --git a/test/integration/generated_path_test.rb b/test/integration/generated_path_test.rb index 91fdeabc..0cf13d54 100644 --- a/test/integration/generated_path_test.rb +++ b/test/integration/generated_path_test.rb @@ -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 diff --git a/test/locales/routes.yml b/test/locales/routes.yml index 9b2d228f..1a59e4b1 100644 --- a/test/locales/routes.yml +++ b/test/locales/routes.yml @@ -5,6 +5,7 @@ es: tr_param: tr_parametro favourites: favoritos blank: "" + slash: foo/bar controllers: people: products: diff --git a/test/routing_test.rb b/test/routing_test.rb index 5b740c81..6904aa9c 100644 --- a/test/routing_test.rb +++ b/test/routing_test.rb @@ -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