Skip to content

Squish username before validation#10239

Merged
Gargron merged 2 commits intomastodon:masterfrom
aurelien-reeves:master
Mar 11, 2019
Merged

Squish username before validation#10239
Gargron merged 2 commits intomastodon:masterfrom
aurelien-reeves:master

Conversation

@aurelien-reeves
Copy link
Copy Markdown
Contributor

Fix #10101

@aurelien-reeves aurelien-reeves changed the title Squish username before validation (#10101) Squish username before validation Mar 11, 2019
Comment thread app/models/account.rb Outdated
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
Copy Markdown
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
Copy Markdown
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