docbrown/app
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
..
assets Add catch to trackFifteenSecondsOnPage() (#15886) 2021-12-28 12:44:36 -05:00
black_box Make Rubocop happy again (#14729) 2021-09-14 09:15:01 -05:00
components/admin/users Small change to make the tools section of member details mobile friendly. (#15159) 2021-10-22 18:47:20 +02:00
controllers Refactoring to consolidate logic (#15851) 2021-12-29 11:08:04 -05:00
decorators role deprecation cleanup (#15717) 2021-12-09 15:27:45 -06:00
errors Guarding against spam from OAuth Sources (#15404) 2021-11-18 16:26:39 -05:00
forms Using a Form Object that will persist for the Creator Settings Form (#15684) 2021-12-10 17:07:40 +02:00
helpers Add crayons_icon_tag helper (#15878) 2022-01-03 09:52:05 +07:00
javascript Bump eslint-config-preact from 1.2.0 to 1.3.0 (#15834) 2021-12-21 14:42:20 +00:00
lib ✂️✂️✂️ Drop PWA (#15781) 2021-12-15 21:25:04 +01:00
liquid_tags Renaming/rearranging constants for clarity (#15911) 2022-01-03 09:30:11 -05:00
mailers ✂✂✂ Remove Connect (#14734) 2021-11-18 08:21:00 -06:00
models Prevent whitespace unicode characters from being used in article title and tag (#14909) 2022-01-03 09:37:03 -05:00
policies Refactoring questions asked of user (#15762) 2021-12-21 12:45:12 -05:00
queries Favoring common method not previously available (#15855) 2021-12-22 11:00:54 -05:00
refinements Drop profile columns from user (#10707) 2020-12-03 08:14:38 +07:00
sanitizers Extracting container for allowed tags & attrs (#15338) 2021-12-16 12:24:45 -05:00
serializers Remove webhooks and related code (#15827) 2021-12-28 10:56:37 +07:00
services Refactoring and documenting class (#15849) 2022-01-03 09:30:41 -05:00
uploaders Added the logo upload to the admin -> customization -> config -> images section. (#15729) 2021-12-15 14:10:27 -05:00
validators Bump rubocop from 1.23.0 to 1.24.0 (#15872) 2021-12-27 10:04:59 -05:00
view_objects Upgrade to Ruby 3.0.2 (#12103) 2021-08-25 14:26:33 -04:00
views Update trusted user welcome email copy with Discord link (#15903) 2021-12-30 12:28:15 -05:00
workers Load article before creating a page view for an invalid one (#15898) 2021-12-29 09:48:34 -06:00