Skip to content

fix: add missing charset encoding for UTF8MB4_0900_BIN#3855

Merged
wellwelwel merged 1 commit into
sidorares:masterfrom
kangsorang:master
Feb 20, 2026
Merged

fix: add missing charset encoding for UTF8MB4_0900_BIN#3855
wellwelwel merged 1 commit into
sidorares:masterfrom
kangsorang:master

Conversation

@kangsorang

@kangsorang kangsorang commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Fix charset encoding mapping for UTF8MB4_0900_BIN

Problem

MySQL2 throws Encoding not recognized: 'undefined' error when connecting to MySQL 8.0+ servers using utf8mb4_0900_bin collation.

Root Cause

Mismatch between charsets.js and charset_encodings.js:

  • charsets.js defines UTF8MB4_0900_BIN = 309
  • charset_encodings.js array has length 309 (indices 0-308)
  • charset_encodings[309] returns undefined
  • Iconv.getDecoder(undefined) throws encoding error

Solution

Add missing encoding mapping for index 309 in charset_encodings.js.

Changes

  • File: lib/constants/charset_encodings.js
  • Change: Add 'utf8' entry at index 309 for UTF8MB4_0900_BIN

Impact

- Fix charset_encodings.js array missing index 309
- Resolves "Encoding not recognized: 'undefined'" error
@codecov

codecov Bot commented Oct 14, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.76%. Comparing base (8143e42) to head (cb79669).
⚠️ Report is 165 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3855      +/-   ##
==========================================
- Coverage   89.78%   89.76%   -0.02%     
==========================================
  Files          86       86              
  Lines       13605    13606       +1     
  Branches     1606     1606              
==========================================
- Hits        12215    12214       -1     
- Misses       1390     1392       +2     
Flag Coverage Δ
compression-0 88.65% <100.00%> (-0.25%) ⬇️
compression-1 86.68% <100.00%> (-3.08%) ⬇️
static-parser-0 87.35% <100.00%> (+<0.01%) ⬆️
static-parser-1 86.93% <100.00%> (-1.19%) ⬇️
tls-0 89.11% <100.00%> (-0.09%) ⬇️
tls-1 88.65% <100.00%> (-0.91%) ⬇️

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wellwelwel

Copy link
Copy Markdown
Collaborator

Thanks, @kangsorang

Do you think it's possible to have a test that covers this case (reproducing the failure if it doesn't have your modification)? Perhaps a temporary table with this encoding would solve it.

@wellwelwel

wellwelwel commented Feb 20, 2026

Copy link
Copy Markdown
Collaborator

Thanks again, @kangsorang! I'll include the following test in a new PR to ensure consistency between A and B to prevent that kind of error:

import { assert, describe, it } from 'poku';
import mysql from '../../../../index.js';

describe('Charset to Encoding coverage', () => {
  const charsets = mysql.Charsets;
  const encodings = mysql.CharsetToEncoding;

  it('every charset ID should have a defined encoding', () => {
    const missing: string[] = [];
    const seen = new Set<number>();

    for (const [name, id] of Object.entries(charsets)) {
      if (typeof id !== 'number' || seen.has(id)) continue;

      seen.add(id);
      if (encodings[id] === undefined) missing.push(`${name} (id=${id})`);
    }

    assert.deepStrictEqual(
      missing,
      [],
      `Missing encoding mappings: ${missing.join(', ')}`
    );
  });
});
Screenshot 2026-02-20 at 08 07 17

@wellwelwel wellwelwel merged commit c9a0dcd into sidorares:master Feb 20, 2026
100 checks passed
mdierolf pushed a commit to CloudQuote/node-mysql2 that referenced this pull request May 23, 2026
- Fix charset_encodings.js array missing index 309
- Resolves "Encoding not recognized: 'undefined'" error

Co-authored-by: sorang <sorang@bithumbcorp.com>
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.

Encoding not recognized: 'undefined' error when connecting to MySQL 8.0+ servers that use utf8mb4_0900_bin collation.

2 participants