Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#27333 closed defect (bug) (invalid)

update_option() truncates the option value

Reported by: bmthemes Owned by:
Priority: normal Milestone:
Component: Database Version: 3.8.1
Severity: normal Keywords:
Cc: Focuses:

Description

When updating an option with a value which contains a special character the value is truncated (example: I tried to insert 'testºthis' and I ended up with only 'test' in the database).

I noticed replacing define('DB_CHARSET', 'utf8'); with define('DB_CHARSET', 'utf-8'); fixed the issue.
Is there a reason 'DB_CHARSET' is set to 'utf8' instead of 'utf-8' ?

Change History (4)

#1 @nacin
13 years ago

  • Milestone Awaiting Review
  • Resolution → invalid
  • Status new → closed

"utf-8" isn't a valid MySQL charset, so I imagine it gets treated as the default charset, like latin1 which will accept anything.

For special four-byte multibyte characters, you can use "utf8mb4" as a charset. See also #21212.

#2 @SergeyBiryukov
13 years ago

  • Component General → Database

The character here is a 2-byte ​masculine ordinal indicator, so #13590 and #21212 appear to be irrelevant.

I could not reproduce the issue. My steps:

  1. Save these lines to a file encoded in UTF-8 and run it:
    include 'wp-load.php';
    
    add_option( 'test', 'testºthis' );
    // echo get_option( 'test' );
    // delete_option( 'test' );
    
  2. Comment out add_option() and uncomment get_option() (to make sure the result comes from the database and not from cache).
  3. The result is testºthis.
  4. Uncomment delete_option() to delete the option.

If the string comes from a file in your case, make sure it's encoded in UTF-8 (without ​byte order mark). If that doesn't help, try inserting the same string with phpMyAdmin to see if the database charset is correct.

Last edited 13 years ago by SergeyBiryukov (previous) (diff)

#4 @bmthemes
13 years ago

The file wasn't coded in UTF-8. I converted in UTF-8 and that solved the issue.
Thanks nacin and Sergey.

Note: See TracTickets for help on using tickets.