Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Added JSON Formatting check for custom translations field #27873

Closed
wants to merge 5 commits into from

Conversation

Pradumn27
Copy link

@Pradumn27 Pradumn27 commented Jan 27, 2023

Proposed changes (including videos or screenshots)

Currently the UI is breaking when an invalid JSON is sent in custom translations. So, I've added the check for valid JSON on the frontend to avoid the UI breaking due to that. Along with that I've also added the valid JSON Formatting check on the saveSettings call at the backend thus ensuring end to end checks for this field.
I've also changed the help text field here to avoid the confusion caused due to that.

Screen.Recording.2023-01-27.at.9.08.06.PM.mov

Issue(s)

Closes #27846

Steps to test or reproduce

  1. Settings
  2. General
  3. Translations
  4. Custom Translations
  5. Add an invalid JSON to the field

Further comments

@Pradumn27 Pradumn27 changed the title [Fix] Custom Translation allows invalid json and break UI (#27846) [Fix] Custom Translation allows invalid json and break UI #27846 Jan 27, 2023
@Pradumn27 Pradumn27 changed the title [Fix] Custom Translation allows invalid json and break UI #27846 [Fix] added JSON Formating check for custom translations field #27846 Jan 27, 2023
@dudanogueira dudanogueira changed the title [Fix] added JSON Formating check for custom translations field #27846 [FIX] added JSON Formating check for custom translations field #27846 Jan 27, 2023
@dudanogueira dudanogueira linked an issue Jan 27, 2023 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Jan 27, 2023

Codecov Report

Merging #27873 (588d6a6) into develop (c8a8f21) will increase coverage by 1.16%.
The diff coverage is 20.00%.

❗ Current head 588d6a6 differs from pull request most recent head 7be631f. Consider uploading reports for the commit 7be631f to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #27873      +/-   ##
===========================================
+ Coverage    42.03%   43.19%   +1.16%     
===========================================
  Files          842      818      -24     
  Lines        17604    17152     -452     
  Branches      2013     1946      -67     
===========================================
+ Hits          7399     7409      +10     
+ Misses        9939     9476     -463     
- Partials       266      267       +1     
Flag Coverage Δ
e2e 43.19% <20.00%> (+1.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@Pradumn27
Copy link
Author

@dudanogueira can you review and merge the PR, Thank you.

@dougfabris dougfabris changed the title [FIX] added JSON Formating check for custom translations field #27846 [FIX] Added JSON Formatting check for custom translations field Mar 1, 2023
Copy link
Member

@matheusbsilva137 matheusbsilva137 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heeey @Pradumn27 ! Thanks for suggesting these changes
Please check #28600

@@ -41,6 +52,9 @@ Meteor.methods({
case 'multiSelect':
check(value, Array);
break;
case 'code':
parseToJSON(value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all code settings are JSON (eg some of them are CSS or HTML). We should check settings' code property to assure they should be a valid JSON.

@@ -6,6 +6,17 @@ import { hasPermission } from '../../../authorization/server';
import { getSettingPermissionId } from '../../../authorization/lib';
import { twoFactorRequired } from '../../../2fa/server/twoFactorRequired';

const parseToJSON = (customTranslations) => {
try {
JSON.parse(customTranslations);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also accept empty strings as valid values for settings, otherwise they can't be erased.

@dougfabris
Copy link
Member

Closing this one in favor of: #28600
Thanks for the contribution @Pradumn27

@dougfabris dougfabris closed this Mar 30, 2023
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.

Custom Translation allows invalid json and break UI
4 participants