Fix profile page rendering when a username contains spaces (#7787)
This commit is contained in:
parent
19056dc9ed
commit
3d313efbd6
5 changed files with 25 additions and 4 deletions
|
|
@ -59,8 +59,7 @@ class UsersController < ApplicationController
|
|||
@user.touch(:profile_updated_at)
|
||||
redirect_to "/settings/#{@tab}"
|
||||
else
|
||||
Honeycomb.add_field("error",
|
||||
@user.errors.messages.reject { |_, v| v.empty? })
|
||||
Honeycomb.add_field("error", @user.errors.messages.reject { |_, v| v.empty? })
|
||||
Honeycomb.add_field("errored", true)
|
||||
render :edit, status: :bad_request
|
||||
end
|
||||
|
|
|
|||
|
|
@ -60,6 +60,8 @@ module URL
|
|||
# @param user [User] the user to create the URL for
|
||||
def self.user(user)
|
||||
url(user.username)
|
||||
rescue URI::InvalidURIError # invalid username containing spaces will result in an error
|
||||
nil
|
||||
end
|
||||
|
||||
def self.organization(organization)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<div class="crayons-card mb-6 p-6 grid gap-6">
|
||||
<div class="flex items-center">
|
||||
<a href="<%= app_url(current_user.username) %>" aria-label="Go to your profile page" class="mr-2">
|
||||
<a href="<%= user_url(current_user) || '#' %>" aria-label="Go to your profile page" class="mr-2">
|
||||
<img src="https://d2fltix0v2e0sb.cloudfront.net/dev-badge.svg" alt="<%= community_name %> badge" height="32" width="32" class="dev-badge crayons-icon" />
|
||||
</a>
|
||||
<p>Add the <%= community_name %> badge to your personal site. <a href="/p/badges">Click here for the code</a>.</p>
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@
|
|||
</h1>
|
||||
<% else %>
|
||||
<h1 class="fs-xl s:fs-3xl">
|
||||
Settings for <a href="<%= user_url(@user) %>">@<%= @user.username.truncate(User::USERNAME_MAX_LENGTH) %></a>
|
||||
Settings for <a href="<%= user_url(@user) || '#' %>">@<%= @user.username.truncate(User::USERNAME_MAX_LENGTH) %></a>
|
||||
</h1>
|
||||
<% end %>
|
||||
</header>
|
||||
|
|
|
|||
20
spec/system/user/user_edits_profile_spec.rb
Normal file
20
spec/system/user/user_edits_profile_spec.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "User edits their profile", type: :system do
|
||||
let(:user) { create(:user, saw_onboarding: true) }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
describe "visiting /settings/profile" do
|
||||
it "renders an error if the username contains spaces and thus is invalid" do
|
||||
visit "/settings/profile"
|
||||
|
||||
fill_in "user[username]", with: "a b c"
|
||||
click_button "Save"
|
||||
|
||||
expect(page).to have_text("Username is invalid")
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue