Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#24180 closed defect (bug) (invalid)

Update option

Reported by: looimaster's profile Looimaster Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:


$widget_text = array (
	2 => array (
		'title' => '',
		'text' => '<div>Copyright &copy; 2000–2013. All right reserved.</div>',
		'filter' => false,
update_option( 'widget_text', $widget_text );

The above returns error on 2000–2013 part (I bet it tries to evaluate that) and database table contains a string that stops at exactly 2000 part (minus is skipped).

WP3.6 alpha.

Change History (6)

#1 @SergeyBiryukov
11 years ago

  • Keywords reporter-feedback added

The above returns error on 2000–2013 part (I bet it tries to evaluate that)

What does it say?

Could not reproduce neither the error nor the incomplete saving. This is what I got in the database:

a:1:{i:2;a:3:{s:5:"title";s:0:"";s:4:"text";s:60:"<div>Copyright &copy; 2000–2013. All right reserved.</div>";s:6:"filter";b:0;}}

The dash here is the en dash, encoded in UTF-8.

  1. Are your database charset and table charset both UTF-8?
  2. Is the file with this code saved in UTF-8 (without byte order mark)?

Related: #21109

#2 @Looimaster
11 years ago

ANSI (Notepad++ set this)
EOL Conversion: Windows

Whatever WAMP for Windows 7 64-bit set.

When I add 2000-2013 instead of just 2000, it stops at that. I don't know what the error is but I know that script stops executing on that update_option() line.

From notepad:

#3 @SergeyBiryukov
11 years ago

In Notepad++, choose "Encoding" > "Convert to UTF-8 without BOM" and save the file. That should fix it.

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

#4 @Looimaster
11 years ago

One more information: I used var_export() in PHP to generate this array. Then Ctrl+C and Ctrl+V to the Notepad++. I can replace that with "dash" character instead of "-" from keyboard. I already managed to make it work :) I'm just reporting it because it may be a bug.

#5 @SergeyBiryukov
11 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version trunk deleted

The issue here is caused by trying to insert a non-UTF-8 character into a UTF-8 database table. MySQL truncates the string at the invalid character.

If the data to be inserted is coming from a file, a simple copy/paste is not enough when dealing with different encodings, you need to make sure the file is encoded in UTF-8 as well.

#6 @Looimaster
11 years ago

Okay! Thanks so much for explanation! I will use UTF-8 without BOM then :)

Note: See TracTickets for help on using tickets.