A platform for community discussion. Free, open, simple.
FIX: Don't throw 500 for invalid website url input
Blake Erickson9cbbaf4237e2
diff --git a/app/services/user_updater.rb b/app/services/user_updater.rbindex 5b3396f1017..cdd5203f969 100644--- a/app/services/user_updater.rb+++ b/app/services/user_updater.rb@@ -149,25 +149,30 @@ class UserUpdatersaved = nil- User.transaction do- if attributes.key?(:muted_usernames)- update_muted_users(attributes[:muted_usernames])- end+ begin+ User.transaction do+ if attributes.key?(:muted_usernames)+ update_muted_users(attributes[:muted_usernames])+ end- if attributes.key?(:ignored_usernames)- update_ignored_users(attributes[:ignored_usernames])- end+ if attributes.key?(:ignored_usernames)+ update_ignored_users(attributes[:ignored_usernames])+ end- name_changed = user.name_changed?- if (saved = (!save_options || user.user_option.save) && user_profile.save && user.save) &&- (name_changed && old_user_name.casecmp(attributes.fetch(:name)) != 0)+ name_changed = user.name_changed?+ if (saved = (!save_options || user.user_option.save) && user_profile.save && user.save) &&+ (name_changed && old_user_name.casecmp(attributes.fetch(:name)) != 0)- StaffActionLogger.new(@actor).log_name_change(- user.id,- old_user_name,- attributes.fetch(:name) { '' }- )+ StaffActionLogger.new(@actor).log_name_change(+ user.id,+ old_user_name,+ attributes.fetch(:name) { '' }+ )+ endend+ rescue Addressable::URI::InvalidURIError => e+ # Prevent 500 for crazy url input+ return savedendDiscourseEvent.trigger(:user_updated, user) if saveddiff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rbindex 5ca012fc135..c18949ab5e7 100644--- a/spec/services/user_updater_spec.rb+++ b/spec/services/user_updater_spec.rb@@ -416,6 +416,15 @@ describe UserUpdater doendend+ context 'when website is invalid' do+ it 'returns an error' do+ user = Fabricate(:user)+ updater = UserUpdater.new(acting_user, user)++ expect(updater.update(website: 'ʔ<')).to eq nil+ end+ end+context 'when custom_fields is empty string' doit "update is successful" douser = Fabricate(:user)