docbrown/spec/models
Derek Crosson ae27d15be7
Prevent whitespace unicode characters from being used in article title and tag (#14909)
* test: whitespace unicode characters cannot be used as titles or tags

* feat: add localized error message

* refactor: use localized error message

* fix: whitespace unicode characters cannot be used as titles or tags

* chore: fix locale after merge

* refactor: fix indentation

* Fix spelling of prohibited in method names

Additionally, rubocop removed a redundant user_id validation since
Article belongs to user.

* Fix spelling

Missed one method call on the same line (fixed the first of two
instances needing changes)

* add failing test cases

The reorganization to remove let was due to a limit on nesting rspec
contexts (it inside context inside describe inside describe when
trying to use different titles in let blocks in contexts)

The first test was clarified (the "U+202D" string that looks like the
code for a unicode point is valid, but the character \u202d is
expected to be invalid

The remaining two tests are based on the feedback I'd given in the PR,
failing because we don't assert title is present after removing
unicode whitespace, and we don't actually set the title (gsub is
non-destructive, returning a value).

* Set title to sanitized title

contains_prohibitied_unicode_characters? was using == (which is not a
good match for strings to regexes), use =~ instead

Change invalid example characters in titles from \u202d (bidi override) to
\u200a (hair space)

Assert that the empty title is blank and can't be blank (even though
it contains no prohibitd characters after replacement)

* change the definition of prohibited characters

From the description, it looks like "unicode space characters" was the
desired rejection set. It was unclear what the existing regex was
matching on (I couldn't get the expected examples to match correctly).

Given the intent, I select "unicode space property, except the ascii
space character", which may _also_ be incorrect but passed the tests.

* Remove now-invalid expectation for presence of user id

Since this was redundant (belongs_to user), we no longer will validate
presence of user id, and we should not test for it.

* Only reject bidirectional text controls

The original issue pointed to the BIDI controls as problematic.

While they called out other "whitespace" characters, as we accept a
wider range of input languages, the need to handle non-printing
punctuation (for example a group separating space for some asian
languages).

It's possible a wider list of characters should be added - if that's
the case I suggest this regex and the sanitization be moved to a
standalone class, and each of the recommendations in
https://www.w3.org/TR/unicode-xml/#Charlist be checked for
applicability.

* Check for blank title after sanitizing disallowed characters

Since validate_title modifies the title, and doesn't set error
messages on the model itself, check for non-empty title _after_
potentially removing any disallowed characters.

* Remove invalid characters before validation

Remove the validate_title and contains_prohibited_characters methods,
and center all logic on the remove prohibitied unicode characters
method.

Remove unneeded and unused arguments (input string is always title,
replacement is always removal/empty string).

* handle case when validating null title

If the title's nil, we don't want to call match? since it will fail.

Title will sometimes be nil when validating.

Co-authored-by: Ben Halpern <bendhalpern@gmail.com>
Co-authored-by: Dan Uber <dan@forem.com>
2022-01-03 09:37:03 -05:00
..
ahoy [deploy] Rubocop: fix Rails/HasManyOrHasOneDependent for Ahoy::Visit and Badge (#9565) 2020-07-31 11:43:50 -04:00
concerns Remove Elasticsearch ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ (#13606) 2021-05-03 11:09:45 -04:00
settings Blocking subdomains of domains marked as spam (#15715) 2021-12-08 14:08:52 -05:00
shared_examples Spelling (#15702) 2021-12-07 06:59:10 -07:00
users Theming cleanup (#15237) 2021-11-09 10:11:55 -05:00
ab_experiment_spec.rb Configurable weighted feed strategy (#15240) 2021-11-29 10:46:56 -05:00
api_secret_spec.rb Limit the Number of API Keys a User Can Have (#7870) 2020-05-15 11:33:02 +02:00
application_record_spec.rb Allow Emails::RemoveOldEmailsWorker to run longer (#15085) 2021-10-15 11:53:55 -04:00
article_destroy_spec.rb [deploy] Rubocop: fix violations of Layout/LineLength (#9197) 2020-07-08 08:36:36 -05:00
article_spec.rb Prevent whitespace unicode characters from being used in article title and tag (#14909) 2022-01-03 09:37:03 -05:00
audit_log_spec.rb Add missing presence validators to models (#10495) 2020-10-01 16:15:32 +02:00
badge_achievement_spec.rb Configure badge credits by admins (#13145) 2021-03-30 10:58:48 +03:00
badge_spec.rb Refactor cache purging (#12811) 2021-03-02 10:09:05 -05:00
banished_user_spec.rb Introduce BanishedUser table (#5589) [deploy] 2020-01-21 17:15:58 -05:00
broadcast_spec.rb Fix Rails/HasManyOrHasOneDependent for Broadcast and Collection (#9662) 2020-08-07 14:27:24 -04:00
collection_spec.rb Fix Rails/HasManyOrHasOneDependent for Broadcast and Collection (#9662) 2020-08-07 14:27:24 -04:00
comment_spec.rb Spelling (#15702) 2021-12-07 06:59:10 -07:00
consumer_app_spec.rb ForemMobile namespaced functions (#15212) 2021-11-23 15:25:29 -06:00
credit_spec.rb Flaky Spec Fix:Remove let_it_be Test Prof Helper (#9556) 2020-07-29 11:31:01 +02:00
data_update_script_spec.rb Save Data Update Script errors to database and show them on http://localhost:3000/admin/data_update_scripts (#12348) 2021-01-21 14:48:34 +01:00
device_spec.rb Add mutable flag to APNS notifcation payload (#14777) 2021-09-21 15:37:43 -05:00
discussion_lock_spec.rb Cooldown Project: Introduce StringAttributeCleaner (#15281) 2021-11-06 14:58:14 +07:00
display_ad_event_spec.rb Spelling (#15702) 2021-12-07 06:59:10 -07:00
display_ad_spec.rb Remove organization dependency and improve display ad UX (#14913) 2021-10-05 08:29:08 -04:00
email_authorization_spec.rb Refactor Admin Member Detail view - Tools section (#14283) 2021-08-17 18:55:53 +02:00
email_message_spec.rb Delete old retained emails after certain period (#14949) 2021-10-12 16:27:13 -04:00
feedback_message_spec.rb Refactor Admin Member Detail view - Tools section (#14283) 2021-08-17 18:55:53 +02:00
follow_spec.rb ✂✂✂ Remove Connect (#14734) 2021-11-18 08:21:00 -06:00
forem_instance_spec.rb Create Settings::SMTP (#13943) 2021-06-14 10:29:43 -04:00
github_issue_spec.rb ✂️ Remove the approvals gem ✂️ (#12978) 2021-03-19 13:28:06 -07:00
github_repo_spec.rb Fix Ruby 2.7 kwargs' warnings & misc spec warnings (#13256) 2021-04-06 16:57:59 -04:00
hair_trigger_spec.rb Ensure ActiveRecord::Base has descendants before checking triggers (#14732) 2021-09-15 09:29:44 -05:00
html_variant_spec.rb Strip surrounding whitespace from HTMLVariant name (#15776) 2021-12-14 14:42:06 -05:00
html_variant_success_spec.rb Unskip all skipped specs (#2941) 2019-05-25 11:04:38 -04:00
html_variant_trial_spec.rb Unskip all skipped specs (#2941) 2019-05-25 11:04:38 -04:00
identity_spec.rb Fixed setting Identity#auth_data_dump in seeds and factory (#15874) 2021-12-28 09:02:15 +03:00
listing_category_spec.rb Rubocop: Fix ListingCategory has_many relation to Listing (#9853) 2020-08-19 19:23:49 +02:00
listing_spec.rb Remove Elasticsearch ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ ✂️ (#13606) 2021-05-03 11:09:45 -04:00
mention_spec.rb Add Mentions::CreateAllWorker for Sidekiq (#5463) 2020-01-13 13:23:30 -06:00
navigation_link_spec.rb Profile generalization: cleanup (#12947) 2021-08-20 16:36:02 +02:00
note_spec.rb [deploy] Add missing dependent clauses to User and cleanup relations (#10011) 2020-08-28 20:19:24 +02:00
notification_spec.rb UsersSettings RFC: Code to Sync User Settings updates to new tables (#13719) 2021-05-27 09:52:54 -04:00
notification_subscription_spec.rb Add missing presence validators to models (#10495) 2020-10-01 16:15:32 +02:00
organization_membership_spec.rb ✂✂✂ Remove Connect (#14734) 2021-11-18 08:21:00 -06:00
organization_spec.rb Rubocop fixes (#14868) 2021-09-30 13:22:09 -04:00
page_spec.rb [15 min fix] Refactor private landing pages model code (#13982) 2021-06-15 18:17:15 +02:00
page_view_spec.rb Remove UserHistory Feature and PageViews from Algolia (#6127) [deploy] 2020-02-18 10:06:30 -05:00
pinned_article_spec.rb Pin posts to feed (#13807) 2021-06-04 10:54:53 +02:00
podcast_episode_appearance_spec.rb Add podcast_appearances joined table (forem#82) (#11354) 2020-11-30 17:12:52 +01:00
podcast_episode_spec.rb [15 min fix] Fallback to the image URL if Cloudinary/Imgproxy are not configured (#13767) 2021-05-19 15:03:20 +02:00
podcast_ownership_spec.rb Podcast ownership join table (MLH Fellowship #81) (#11410) 2020-11-19 12:41:17 +01:00
podcast_spec.rb Podcast ownership join table (MLH Fellowship #81) (#11410) 2020-11-19 12:41:17 +01:00
poll_option_spec.rb Add missing presence validators to models (#10495) 2020-10-01 16:15:32 +02:00
poll_skip_spec.rb Refactoring poll/vote/skip logic (#15441) 2021-11-29 10:52:32 -05:00
poll_spec.rb Refactoring poll/vote/skip logic (#15441) 2021-11-29 10:52:32 -05:00
poll_vote_spec.rb Refactoring poll/vote/skip logic (#15441) 2021-11-29 10:52:32 -05:00
profile_field_group_spec.rb Replace calls to Flipper with FeatureFlag (#11386) 2020-11-12 14:15:33 +01:00
profile_field_spec.rb Profile generalization cleanup phase 2 (#14555) 2021-08-27 09:17:26 +07:00
profile_pin_spec.rb Flaky Spec Fix:Remove let_it_be Test Prof Helper (#9556) 2020-07-29 11:31:01 +02:00
profile_spec.rb Remove check_box type from profile fields (#14832) 2021-09-30 13:27:39 -04:00
rating_vote_spec.rb [deploy] Add missing foreign keys to models related to users (#10018) 2020-08-31 15:39:57 +02:00
reaction_spec.rb Refactoring Spam Handler (#15412) 2021-11-30 12:45:12 -05:00
response_template_spec.rb [deploy] Rubocop: fix violations of Layout/LineLength (#9197) 2020-07-08 08:36:36 -05:00
role_spec.rb ✂✂✂ Remove Connect (#14734) 2021-11-18 08:21:00 -06:00
sponsorship_spec.rb Only permit valid class names as sponsorable type (#14387) 2021-11-05 12:25:35 -05:00
tag_adjustment_spec.rb [deploy] Rubocop: fix violations of Layout/LineLength (#9197) 2020-07-08 08:36:36 -05:00
tag_spec.rb Prevent whitespace unicode characters from being used in article title and tag (#14909) 2022-01-03 09:37:03 -05:00
timeframe_spec.rb Remove timeframer from app/labor (#11782) 2020-12-08 12:52:33 +07:00
tweet_spec.rb Spelling (#15702) 2021-12-07 06:59:10 -07:00
user_block_spec.rb Fix and refactor hide user content (#12307) 2021-01-18 11:08:23 -05:00
user_role_spec.rb [Search 2.0] Users (#13453) 2021-04-24 19:06:06 +02:00
user_spec.rb Remove webhooks and related code (#15827) 2021-12-28 10:56:37 +07:00
user_subscription_spec.rb Spelling (#15702) 2021-12-07 06:59:10 -07:00