WordPress.org

Make WordPress Core

Opened 12 months ago

Closed 12 months ago

Last modified 12 months ago

#24180 closed defect (bug) (invalid)

Update option

Reported by: Looimaster Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

$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)

comment:1 SergeyBiryukov12 months 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

comment:2 Looimaster12 months ago

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

Database:
Whatever WAMP for Windows 7 64-bit set.

http://gyazo.com/5d82eeb144241ac61f60bbc21212708c.png

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:

http://gyazo.com/2aff28ec8364f074e8c5035fc1e3a97b.png

comment:3 SergeyBiryukov12 months ago

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

Last edited 12 months ago by SergeyBiryukov (previous) (diff)

comment:4 Looimaster12 months 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.

comment:5 SergeyBiryukov12 months 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.

comment:6 Looimaster12 months ago

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

Note: See TracTickets for help on using tickets.