Skip to content

fix: render EAN barcodes with the correct format - #14322

Open
TaciteOFF wants to merge 2 commits into
openfoodfacts:mainfrom
TaciteOFF:fix/render-ean-barcodes
Open

fix: render EAN barcodes with the correct format#14322
TaciteOFF wants to merge 2 commits into
openfoodfacts:mainfrom
TaciteOFF:fix/render-ean-barcodes

Conversation

@TaciteOFF

@TaciteOFF TaciteOFF commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • render 13-digit product codes as EAN-13;
  • render 8-digit product codes as EAN-8;
  • keep Code 128 as the fallback for non-standard or internal product codes;
  • update the affected HTML integration snapshots.

Context

The product page currently uses JsBarcode with the auto format. JsBarcode does not detect EAN formats automatically: when Code 128 is available, auto selects it. As a result, a product such as 3600542656733 is labelled as EAN-13 but displayed as Code 128.

The barcode is generated as an SVG in the browser, so this change does not require any product recomputation or data migration.

Tests

  • git diff --check
  • verified that JsBarcode 3.12.3 accepts 3600542656733 as EAN-13 and produces the expected 95-module encoding;
  • updated the expected HTML integration results.

@TaciteOFF
TaciteOFF requested a review from a team as a code owner August 22, 2026 14:43
@github-project-automation github-project-automation Bot moved this to To discuss and validate in 🍊 Open Food Facts Server issues Aug 22, 2026
@github-actions github-actions Bot added Product Page 🧪 tests Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. labels Aug 22, 2026
@codecov-commenter

codecov-commenter commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.49%. Comparing base (0c7be85) to head (c1107ae).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14322      +/-   ##
==========================================
+ Coverage   50.30%   55.49%   +5.18%     
==========================================
  Files         103      104       +1     
  Lines       26398    26456      +58     
  Branches     6315     6324       +9     
==========================================
+ Hits        13280    14681    +1401     
+ Misses      11357     9850    -1507     
- Partials     1761     1925     +164     
Flag Coverage Δ
integration-test-group-1 13.09% <ø> (?)
integration-test-group-2 9.21% <ø> (?)
integration-test-group-3 9.38% <ø> (?)
integration-test-group-4 33.42% <ø> (?)
integration-test-group-5 28.77% <ø> (?)
integration-test-group-6 9.14% <ø> (?)
integration-test-group-7 9.63% <ø> (?)
integration-test-group-8 28.31% <ø> (?)
integration-test-group-9 26.64% <ø> (?)
unit-test-group-1 25.02% <ø> (ø)
unit-test-group-2 31.28% <ø> (ø)
unit-test-group-3 33.59% <ø> (ø)
unit-test-group-4 22.29% <ø> (ø)
unit-test-group-5 28.30% <ø> (ø)
unit-test-group-6 21.52% <ø> (ø)

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

JsBarcode refuses to render a value that does not validate against the
requested format: it throws an InvalidInputException and nothing is drawn.

Since codes assigned by assign_new_code() are sequential from
2000000000001, most of them have an invalid EAN-13 check digit, and so do
codes entered with a typo. Forcing the EAN13/EAN8 format would have made
their barcode disappear from the product page.

Catch the exception and re-render with CODE128 in that case, which is what
the previous "auto" format always used.
@sonarqubecloud

Copy link
Copy Markdown

@Freso Freso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

@github-project-automation github-project-automation Bot moved this from To discuss and validate to Done in 🍊 Open Food Facts Server issues Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product Page Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🧪 tests

Projects

Development

Successfully merging this pull request may close these issues.

4 participants