[TYPO3-dev] Your opinion about a possible bug in t3lib_cs

Francois Suter fsuter at cobweb.ch
Mon Dec 8 21:05:42 CET 2008


Hi all,

I found a behavior in t3lib_cs which looks like a bug. On the other hand 
I may have misunderstood the API, so I wanted to have some opinions 
before submitting an abusive patch. Here's the thing:

- t3lib_cs contains a table of synonyms for many charsets. This makes it 
possible, for example, to enter "utf8" and it gets interpreted to "utf-8".
- there's a method to handle that transformation called 
t3lib_cs::parse_charset().

Now let's say I'm doing the following call:

$someString = 'Weird chåractêrs';
$cleanString = $GLOBALS['LANG']->csConvObj->specCharsToASCII('utf8', 
$someString);

$cleanString will come out as 'Weird chåractêrs' too, without 
transformation, instead of the expected result: 'Weird characters'.

This is due to the fact that t3lib_cs::specCharsToASCII() expects the 
encoding to be spelled strictly, i.e. 'utf-8' and not 'utf8'. If 
t3lib_cs::specCharsToASCII() called t3lib_cs::parse_charset() internally 
it would find the right name for the encoding and do the expected 
transformation.

So which answer is correct:

a) it's a bug, t3lib_cs::specCharsToASCII() (and quite a few other 
functions actually) should call t3lib_cs::parse_charset() (thus hiding 
the ugly details from the developer).

b) it's the developer's responsibility to call t3lib_cs::parse_charset() 
himself before passing an encoding code to any of the t3lib_cs methods.

The more I think about it, the more I suppose the correct answer is b), 
but it seems to me that a proper API would rather behave like a).

Cheers

-- 

Francois Suter
Cobweb Development Sarl - http://www.cobweb.ch




More information about the TYPO3-dev mailing list