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
Merged

Conversation

aurelien-reeves
Copy link
Contributor

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

@aurelien-reeves aurelien-reeves Mar 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mastodon:master Mar 11, 2019
hiyuki2578 pushed a commit to ProjectMyosotis/mastodon that referenced this pull request Oct 2, 2019
* Squish username before validation (mastodon#10101)

Fix mastodon#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.
messenjahofchrist pushed a commit to Origin-Creative/mastodon that referenced this pull request Jul 30, 2021
* Squish username before validation (mastodon#10101)

Fix mastodon#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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants