Skip to content

Commit 2b9830d

Browse files
authored
Redirecting with trailing slash with query parameters (tricknotes#595)
Fixes the bug when redirecting with trailing slash with query parameters resulting in an invalid url eg: https://app.com?query=foo would redirect to https://app.com?query=foo/, which is invalid This PR fixes this issue adding the trailing slash before the query parameters eg: https://app.com?query=foo would be redirected to https://app.com/?query=foo In order to retain a passing test suite, use ember-new-output v4.0.0.
1 parent d68d804 commit 2b9830d

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

bin/setup_ember

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ setup_ember() {
66
local target="${1-spec/dummy/my-app}"
77

88
if ! [ -d $target ]; then
9-
git clone -b stable https://github.com/ember-cli/ember-new-output.git $target
9+
git clone -b 'v4.0.0' https://github.com/ember-cli/ember-new-output.git $target
1010

1111
echo '-- Make router catchall routes'
1212
sed -i -e 's/auto/hash/' $target/config/environment.js

lib/ember_cli/route_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def mount_ember_app(app_name, to:, **options)
1919
redirect_if_missing_trailing_slash = {
2020
constraints: EmberCli::TrailingSlashConstraint.new,
2121
to: redirect(-> (_, request) {
22-
File.join(request.original_fullpath, "")
22+
File.join(request.path, "/?#{request.query_parameters.to_query}")
2323
}),
2424
}
2525

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module EmberCli
22
class TrailingSlashConstraint
33
def matches?(request)
4-
!request.original_fullpath.to_s.ends_with?("/")
4+
!request.original_fullpath.to_s.split("?").first.end_with?("/")
55
end
66
end
77
end

spec/features/user_views_ember_app_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@
4343
expect(current_path).to eq("/asset-helpers/")
4444
end
4545

46+
scenario "is redirected with trailing slash with query params", js: false do
47+
expect(embedded_path(query: "foo")).to eq("/asset-helpers?query=foo")
48+
49+
visit embedded_path(query: "foo")
50+
51+
expect(page).to have_current_path("/asset-helpers/?query=foo")
52+
end
53+
54+
scenario "is not redirected with trailing slash with params", js: false do
55+
expect(embedded_path(query: "foo")).to eq("/asset-helpers?query=foo")
56+
57+
visit "/asset-helpers/?query=foo"
58+
59+
expect(page).to have_current_path("/asset-helpers/?query=foo")
60+
end
61+
4662
def have_client_side_asset
4763
have_css %{img[src*="logo.png"]}
4864
end

0 commit comments

Comments
 (0)