docbrown/config
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
..
environments Spelling (#15702) 2021-12-07 06:59:10 -07:00
fastly/snippets Disallow null user agent and obsolete browser (#15817) 2021-12-17 15:02:30 -05:00
initializers Bump rubocop from 1.23.0 to 1.24.0 (#15872) 2021-12-27 10:04:59 -05:00
locales Prevent whitespace unicode characters from being used in article title and tag (#14909) 2022-01-03 09:37:03 -05:00
routes Remove webhooks and related code (#15827) 2021-12-28 10:56:37 +07:00
webpack Added the babel-inline-react-svg plugin (#15461) 2021-11-23 12:24:50 -05:00
application.rb Load any translation files in subdirectories (#15077) 2021-10-14 11:17:07 -05:00
blazer.yml Increase Blazer's timeout (#15427) 2021-11-18 14:50:18 -05:00
boot.rb Upgrade to Rails 6.0 (#7658) 2020-06-04 11:54:25 +02:00
cable.yml Upgrade Rails to 5.2.3 (#1408) 2019-04-03 13:08:59 -04:00
database.yml Update database config (#11308) 2021-02-23 17:41:34 -05:00
environment.rb Rails 6: enable zeitwerk autoloader (#8766) 2020-06-22 16:27:55 +02:00
field_test.yml Spelling (#15702) 2021-12-07 06:59:10 -07:00
i18n-tasks.yml Remove Doorkeeper gem (#15749) 2021-12-21 12:29:58 +07:00
puma.rb Upgrade Rails to 6.1.3.1 (#11333) 2021-04-05 10:39:48 -04:00
routes.rb Remove webhooks and related code (#15827) 2021-12-28 10:56:37 +07:00
schedule.yml Spelling fixes to live code (#15670) 2021-12-06 12:11:25 +02:00
secrets.yml Initial commit 2018-02-28 16:11:08 -05:00
sidekiq.yml setup sidekiq queues for different priority jobs (#5300) [deploy] 2019-12-30 10:16:52 -06:00
spring.rb Upgrade Rails to 6.1.3.1 (#11333) 2021-04-05 10:39:48 -04:00
storage.yml Upgrade Rails to 5.2.3 (#1408) 2019-04-03 13:08:59 -04:00
webpacker.yml Moved from resolved_paths (deprecated) to additional_paths. (#9982) 2020-08-24 16:08:16 -04:00