Skip to content

Fix: Improve Charset Handling in wpdb::get_table_charset Method#7662

Open
Debarghya-Banerjee wants to merge 3 commits intoWordPress:trunkfrom
Debarghya-Banerjee:fix/update-get_table_charset-method
Open

Fix: Improve Charset Handling in wpdb::get_table_charset Method#7662
Debarghya-Banerjee wants to merge 3 commits intoWordPress:trunkfrom
Debarghya-Banerjee:fix/update-get_table_charset-method

Conversation

@Debarghya-Banerjee
Copy link
Copy Markdown

Trac Ticket: Core-59868

Summary

  • This pull request addresses an issue with the wpdb::get_table_charset function regarding character set determination for database tables with mixed charset definitions. The previous implementation prioritized utf8 when both utf8 and utf8mb4 were present, leading to potential data loss for 4-byte characters (e.g., emojis). This change ensures that utf8mb4 is used when applicable.

Changes Made

Updated Charset Logic:

  • The logic in the get_table_charset function was modified to return utf8mb4 when both utf8 and utf8mb4 character sets are detected in the table's columns.

  • This ensures that columns defined with utf8mb4 can store all valid characters, including 4-byte characters.

Test Updates:

  • Adjusted the test cases in Tests_DB_Charset::test_get_table_charset to reflect the new behavior, specifically modifying expectations where the charset was previously set to utf8 when utf8mb4 should now be expected.

Rationale

  • The changes are crucial for maintaining data integrity and supporting modern applications that require the storage of a wider range of characters. By ensuring that the database can correctly handle 4-byte characters, we prevent potential insert errors and improve the overall robustness of the character handling in WordPress.

Impact

  • This improvement should enhance compatibility with rich media content and internationalization, benefiting developers and users alike.

Testing

  • Updated tests to reflect new charset logic.

  • All tests have been run and passed successfully.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 28, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props debarghyabanerjee, apermo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Copy Markdown

@apermo apermo left a comment

Choose a reason for hiding this comment

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

Other than the likely by accident added empty line. Looking good to me.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Copy Markdown

@apermo apermo left a comment

Choose a reason for hiding this comment

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

Looking good to me

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.

2 participants