docbrown/app
Jeremy Friesen 3253ba2c7a
Patching ERB rendering of the data-info JSON (#16067)
Prior to this commit, we were somewhat naively rendering Hash style data
attributes in our ERB templates.  By rendering each hash attribute
separately, we were rendering characters that could break the
javascript (e.g. double hack or backslash `"` or `\`).

By moving to this view_object rendering, we leverage Rails's `to_json`
behavior to ensure properly escaped values.  As part of this exercise, I
generalized the method to allow for other places to benefit from this
behavior.

This generalization also helps ensure that we have a more conformant
rendering (e.g. we should always have an :id, :className, and :name
value in our data-info hash).

_Note: I've updated the user's names for Cypress tests as they are more
likely to catch the particular issue than anything else.  I assume that
I'm going to break some cypress tests and will need some help fixing
them._

Closes #15916, #14704

Supersedes #15983

How to test locally:

Assuming you have seeded database (e.g. `rails db:seed`), checkout the
"main" branch.  Then in `rails console` find a user that's written articles:

```ruby
user = Article.last.user

user.update(name: "\\: #{user.name}")

user.articles.each(&:save)
```

Now, again on the "main" branch, start your application (e.g.,
`bin/startup`).

Then get a logged in and a logged out browser session going.  Open your
web inspector and open console.  Then go to the local instances homepage
(e.g., http://localhost:3000) and look for JS errors.

On the main branch, you should see an exception around
`JSON.parse(button.data.info)` (assuming that the `user`'s article is
rendered on the homepage).

Then go to the user's page (e.g. https://localhost:3000/:user-slug) and
look for JS parse errors.

On this PR's branch (e.g.,
`jeremyf/take-two-at-resolving-gh-15916`)
you shouldn't see those console errors.

More importantly, the Follow buttons should work.
2022-01-14 08:30:49 -05:00
..
assets Patching ERB rendering of the data-info JSON (#16067) 2022-01-14 08:30:49 -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 Change feed query limit to 25 (#16082) 2022-01-12 17:54:55 -05:00
decorators Patching ERB rendering of the data-info JSON (#16067) 2022-01-14 08:30:49 -05:00
errors small non-views ruby i18n (#16004) 2022-01-11 10:05:18 +07:00
forms Using a Form Object that will persist for the Creator Settings Form (#15684) 2021-12-10 17:07:40 +02:00
helpers Patching ERB rendering of the data-info JSON (#16067) 2022-01-14 08:30:49 -05:00
javascript Update storybook node version (#16106) 2022-01-14 08:00:39 -05:00
lib Login with Google (#15986) 2022-01-13 10:25:52 -06:00
liquid_tags Complete implementation; add specs (#16081) 2022-01-12 15:45:59 -05:00
mailers ✂✂✂ Remove Connect (#14734) 2021-11-18 08:21:00 -06:00
models Patching ERB rendering of the data-info JSON (#16067) 2022-01-14 08:30:49 -05:00
policies small non-views ruby i18n (#16004) 2022-01-11 10:05:18 +07:00
queries small non-views ruby i18n (#16004) 2022-01-11 10:05:18 +07: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 Refactoring to add helper method (#16064) 2022-01-12 11:21:44 -05:00
services Turn featured back on as query scoring weight (#16093) 2022-01-14 07:32:52 -05:00
uploaders small non-views ruby i18n (#16004) 2022-01-11 10:05:18 +07:00
validators Bump rubocop from 1.23.0 to 1.24.0 (#15872) 2021-12-27 10:04:59 -05:00
view_objects Patching ERB rendering of the data-info JSON (#16067) 2022-01-14 08:30:49 -05:00
views Patching ERB rendering of the data-info JSON (#16067) 2022-01-14 08:30:49 -05:00
workers Login with Google (#15986) 2022-01-13 10:25:52 -06:00