Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-09-11 21:01:15

ecklesroad
Plugin Author
From: Bemidji, MN
Registered: 2008-02-22
Posts: 119
Website

strange error started reported iconv() in txplib_misc.php

I’ve been getting strange errors being reported on one of my TXP 4.5.5 sites in the last day:


An error occurred: 

error - 2014-09-11 15:37:08 --> Severity: Notice  --> iconv(): Wrong charset, conversion from `1252' to `UTF-8' is not allowed /home/grchamb/public_html/textpattern/lib/txplib_misc.php 1606
URI: /textpattern/?event=article
DOMAIN: grchamb.pbndev.net
REMOTE IP: 209.191.220.141
GET VARIABLES:
-----------------------------------------
"event": article

this happens on any page that using safe_strftime(), which I’d guess is a lot from the look of my error reports. Any idea what’s going on?

Offline

#2 2014-09-12 05:10:29

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: strange error started reported iconv() in txplib_misc.php

This is the first time I’ve heard of this error but a web search returned this discussion which explains what might be causing it.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2014-09-12 07:33:01

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,134
GitHub

Re: strange error started reported iconv() in txplib_misc.php

Some interesting comment discussions here, too: php.net/manual/en/function.iconv.php

Offline

#4 2014-09-12 19:50:41

ecklesroad
Plugin Author
From: Bemidji, MN
Registered: 2008-02-22
Posts: 119
Website

Re: strange error started reported iconv() in txplib_misc.php

Weird. I’m not able to look at the code right now but does/should txp run setlocal() anywhere in the backend?

Offline

#5 2014-09-17 14:44:48

ecklesroad
Plugin Author
From: Bemidji, MN
Registered: 2008-02-22
Posts: 119
Website

Re: strange error started reported iconv() in txplib_misc.php

Found some interesting stuff, at least for my situation. There’s a bug which has been in PHP for a long time where iconv will spit out error even though error reporting is supposed be suppressed for the $new = iconv($charset, 'UTF-8', $str); line.

The issue I was running into was that just above that line 1606 there’s a check for elseif (IS_WIN and is_numeric($charset)). I var_dumped my PHP_OS and $charset, my os is set as “Linux” and the $charset is set to “1252” so that conditions never passes and the $charset never gets set to “Windows-1252” like it should.

Offline

#6 2014-09-17 15:31:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: strange error started reported iconv() in txplib_misc.php

ecklesroad wrote #283825:

The issue I was running into was that just above that line 1606 there’s a check for elseif (IS_WIN and is_numeric($charset)). I var_dumped my PHP_OS and $charset, my os is set as “Linux” and the $charset is set to “1252” so that conditions never passes and the $charset never gets set to “Windows-1252” like it should.

Interesting. All this locale / character encoding stuff is confusing to mere mortals such as myself.

To recap, there are two issues here:

  1. Your server OS is Linux but it’s using Windows-1252 encoding.
  2. The bug in PHP causes an error to be thrown when iconv can’t convert the charset from 1252 to UTF-8 because the charset is “wrong” and error suppression doesn’t work.

So what’s the workaround here? Add a test for non-win systems that have all-numeric $charset values and prepend Windows- to them? Change the current code to ignore OS? Fix the original $charset value in your system somehow, perhaps through better setlocale() code at the start of the page? Change the admin side meta tags to correctly reflect the charset in use? Something else?

I’m at a bit of a loss here about which way to proceed. Any help appreciated.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2014-09-19 17:57:06

ecklesroad
Plugin Author
From: Bemidji, MN
Registered: 2008-02-22
Posts: 119
Website

Re: strange error started reported iconv() in txplib_misc.php

@Bloke I had to do two things. You can see my “fix” here https://gist.github.com/withremote/effb1364e5e2a6d1f4f9. I have this on one of my live sites and it seems to have done the trick.

The first problems my PHP_OS came up as Linux and my $charset was numeric, so the check for “if windows and if character set is numeric prepped Windows- to the character set string” would never be true. So I added an additional check for “if my character set is one of the two valid php windows character sets, 1251 or 1252”

The second was with iconv itself. iconv does not listen to the error suppression/scream , it a bug in PHP that has been reported numerous times and never fixed. The workaround was to use mb_convert_encoding in place of iconv. Without doing this iconv with raise a notice error instead of being ignored like it should.

Offline

Board footer

Powered by FluxBB