Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squish username before validation #10239

Merged
merged 2 commits into from Mar 11, 2019

Conversation

@aurelien-reeves
Copy link
Contributor

commented Mar 11, 2019

Fix #10101

Fix #10101
@aurelien-reeves aurelien-reeves changed the title Squish username before validation (#10101) Squish username before validation Mar 11, 2019
@@ -78,6 +78,10 @@ class Account < ApplicationRecord
validates :note, note_length: { maximum: 160 }, if: -> { local? && will_save_change_to_note? }
validates :fields, length: { maximum: 4 }, if: -> { local? && will_save_change_to_fields? }

before_validation(on: :create) do

This comment has been minimized.

Copy link
@Gargron

Gargron Mar 11, 2019

Member

Style-wise, it would be preferable to do it via a private method

before_validation :prepare_username, on: :create

I am also not sure what squish gives here over strip, would prefer to just use strip

This comment has been minimized.

Copy link
@aurelien-reeves

aurelien-reeves Mar 11, 2019

Author Contributor

Indeed, I will move before_validation into a private method.

Regarding squish, actually it processes unicode whitespaces. strip does not.

pry(main)> "\u3000test\u00a0".strip
=> " test "
pry(main)> "\u3000test\u00a0".squish
=> "test"

If you agree to use squish to process Unicode white-spaces, I will add a dedicated test for that, or at least I will add Unicode white-spaces into the test I already have added.

Also add Unicode wite-spaces to the spec to support the use of squish
over strip.
@Gargron Gargron merged commit 85537b0 into tootsuite:master Mar 11, 2019
11 checks passed
11 checks passed
ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: check-i18n Your tests passed on CircleCI!
Details
ci/circleci: install Your tests passed on CircleCI!
Details
ci/circleci: install-ruby2.4 Your tests passed on CircleCI!
Details
ci/circleci: install-ruby2.5 Your tests passed on CircleCI!
Details
ci/circleci: install-ruby2.6 Your tests passed on CircleCI!
Details
ci/circleci: test-ruby2.4 Your tests passed on CircleCI!
Details
ci/circleci: test-ruby2.5 Your tests passed on CircleCI!
Details
ci/circleci: test-ruby2.6 Your tests passed on CircleCI!
Details
ci/circleci: test-webui Your tests passed on CircleCI!
Details
codeclimate All good!
Details
hiyuki2578 added a commit to ProjectMyosotis/mastodon that referenced this pull request Oct 2, 2019
* Squish username before validation (tootsuite#10101)

Fix tootsuite#10101

* Move before_validation hook to a private method

Also add Unicode wite-spaces to the spec to support the use of squish
over strip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.