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: js and json lang quotes escape #9822

Merged
merged 8 commits into from
Mar 6, 2024
Merged

Conversation

alexgarel
Copy link
Member

@alexgarel alexgarel commented Feb 21, 2024

Translations coming from crowdin might contain single quotes or double quotes. So whenever we use lang in a json or javascript string we should escape quotes.

I created edq and esq (Escape Single/Double Quotes) function for that (1st commit) and applied it in a lot of place (2nd commit). This should be the pattern to use from now on.

fixes:

Note: I will do a hotfix in prod for the remove account case, because it's important to fix quickly (GDPR).

@alexgarel alexgarel marked this pull request as ready for review February 21, 2024 17:32
@alexgarel alexgarel requested a review from a team as a code owner February 21, 2024 17:32
@github-actions github-actions bot added Product Page 📦 Packaging https://wiki.openfoodfacts.org/Category:Recycling product history We have kept 10 years of product revisions. This is useful to monitor edits & product improvements 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels JavaScript 🗺️ Maps Nova - Ultra-processed foods NOVA is an indicator for food ultra-processing https://world.openfoodfacts.org/nova 🏭 Producers Platform https://wiki.openfoodfacts.org/Platform_for_producers Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🌱 Green-Score https://world.openfoodfacts.org/eco-score-the-environmental-impact-of-food-products Agribalyse French LCA database used in Eco-Score computations Display 👥 Users lang Lists of products ingredients analysis 🚦 Nutri-Score 👮 Moderation Site layout 🔎 Search Nutrient levels labels Feb 21, 2024
@alexgarel alexgarel force-pushed the fix-js-lang-quotes-escape branch from 1baeaba to 012b8f2 Compare February 21, 2024 17:59
@alexgarel
Copy link
Member Author

This is a big PR ! I still have to double read my changes to be sure.

@alexgarel
Copy link
Member Author

Ideally we should add a check that we don't use lang / f_lang without edq or esq if we are inside quotes. (but I don't think of an easy way to do this).

@alexgarel
Copy link
Member Author

This is ready for review & merge @stephanegigandet

@@ -5736,12 +5740,21 @@ sub search_and_export_products ($request_ref, $query_ref, $sort_by) {
return;
}

sub escape_char($s, $char) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good. Maybe this function (and escape_single_quote) could be moved to Text.pm

Copy link
Contributor

@stephanegigandet stephanegigandet left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

@github-actions github-actions bot added the Text label Mar 6, 2024
@alexgarel alexgarel enabled auto-merge (squash) March 6, 2024 10:08
Copy link

sonarqubecloud bot commented Mar 6, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

sonarqubecloud bot commented Mar 6, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@alexgarel alexgarel merged commit a3fcac9 into main Mar 6, 2024
12 checks passed
@alexgarel alexgarel deleted the fix-js-lang-quotes-escape branch March 6, 2024 11:38
john-gom pushed a commit that referenced this pull request May 24, 2024
Translations coming from crowdin might contain single quotes or double quotes. So whenever we use lang in a json or javascript string we should escape quotes.

I created edq and esq (Escape Single/Double Quotes) function for that (1st commit) and applied it in a lot of place (2nd commit). This should be the pattern to use from now on. 

fixes: 
- #9820
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Agribalyse French LCA database used in Eco-Score computations Display ✏️ Editing 🌱 Green-Score https://world.openfoodfacts.org/eco-score-the-environmental-impact-of-food-products ingredients analysis JavaScript 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels lang Lists of products 🗺️ Maps 👮 Moderation Nova - Ultra-processed foods NOVA is an indicator for food ultra-processing https://world.openfoodfacts.org/nova 🚦 Nutri-Score Nutrient levels 📦 Packaging https://wiki.openfoodfacts.org/Category:Recycling 🏭 Producers Platform https://wiki.openfoodfacts.org/Platform_for_producers product history We have kept 10 years of product revisions. This is useful to monitor edits & product improvements Product Page 🔎 Search Site layout Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. Text 👥 Users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants