FIX: Redirects containing Unicode usernames didn't work

This commit is contained in:
Gerhard Schlager
2020-06-05 18:31:58 +02:00
parent f6628e4f43
commit 8c6a42c589
12 changed files with 96 additions and 19 deletions

View File

@@ -760,7 +760,7 @@ class ApplicationController < ActionController::Base
return if !current_user
return if !should_enforce_2fa?
redirect_path = "#{GlobalSetting.relative_url_root}/u/#{current_user.username}/preferences/second-factor"
redirect_path = path("/u/#{current_user.encoded_username}/preferences/second-factor")
if !request.fullpath.start_with?(redirect_path)
redirect_to path(redirect_path)
nil

View File

@@ -7,7 +7,7 @@ class EmailController < ApplicationController
before_action :ensure_logged_in, only: :preferences_redirect
def preferences_redirect
redirect_to(email_preferences_path(current_user.username_lower))
redirect_to path("/u/#{current_user.encoded_username}/preferences/emails")
end
def unsubscribe

View File

@@ -109,7 +109,7 @@ class UserAvatarsController < ApplicationController
if !Discourse.avatar_sizes.include?(size) && Discourse.store.external?
closest = Discourse.avatar_sizes.to_a.min { |a, b| (size - a).abs <=> (size - b).abs }
avatar_url = UserAvatar.local_avatar_url(hostname, user.username_lower, upload_id, closest)
avatar_url = UserAvatar.local_avatar_url(hostname, user.encoded_username(lower: true), upload_id, closest)
return redirect_to cdn_path(avatar_url)
end
@@ -117,7 +117,7 @@ class UserAvatarsController < ApplicationController
upload ||= user.uploaded_avatar if user.uploaded_avatar_id == upload_id
if user.uploaded_avatar && !upload
avatar_url = UserAvatar.local_avatar_url(hostname, user.username_lower, user.uploaded_avatar_id, size)
avatar_url = UserAvatar.local_avatar_url(hostname, user.encoded_username(lower: true), user.uploaded_avatar_id, size)
return redirect_to cdn_path(avatar_url)
elsif upload && optimized = get_optimized_image(upload, size)
if optimized.local?

View File

@@ -130,7 +130,7 @@ class UsersController < ApplicationController
end
def user_preferences_redirect
redirect_to email_preferences_path(current_user.username_lower)
redirect_to path("/u/#{current_user.encoded_username}/preferences")
end
def update
@@ -273,7 +273,7 @@ class UsersController < ApplicationController
cookies[:destination_url] = path("/my/#{params[:path]}")
redirect_to path("/login-preferences")
else
redirect_to(path("/u/#{current_user.username}/#{params[:path]}"))
redirect_to(path("/u/#{current_user.encoded_username}/#{params[:path]}"))
end
end