Problems with accented characters

Tommy Sundstrom - October 7, 2004 - 08:51
Project:Textile
Component:Code
Category:bug report
Priority:normal
Assigned:jhriggs
Status:closed
Description

There is a problem with accented characters when using the textile module, see http://drupal.org/node/10268 and http://drupal.org/node/6881

I belive the options['char_encoding'] should be set to 0 as default OR that a trouble shooting section should be added to the installation instructions telling about this solution.

Possibly related: option charset is set to iso-8859-1. I thougt Drupal was strictly utf-8.

#1

pablobm - October 29, 2004 - 15:21

Yesterday I had a hard fight against this module due to this problem. Finally, I think I came up with the error.

Initially, it may seem the problem is the module doesn't tell to Textile to work with UTF-8 encoding, which is the one used by Drupal.
It should be fixed in the code at the end of the module, inside the DrupalTextile class. (This is because all Drupal processing is supposed to deal with UTF-8).

One way to do so would be changing the next code (from line 516):

<?php
   
function process($in_string) {
    return
preg_replace('{(<a href=")(#[^"]*")}', '$1' . request_uri() . '$2', parent::process($in_string));
  }
// function process
?>

Should be changed to this:

<?php
   
function process($in_string) {
   
$this->charset('utf8'); // This is the important change
   
return preg_replace('{(<a href=")(#[^"]*")}', '$1' . request_uri() . '$2', parent::process($in_string));
  }
// function process
?>

However, this is not enough. There is an error in the textilephp/Textile.php as well. The author forgets that in PHP, 0 !== NULL but 0 == NULL. This happens in the next piece of code (from line 4080):

<?php
 
function char_encoding($char_encoding = NULL) {
    if (
$char_encoding != NULL) {
     
$this->options['char_encoding'] = $char_encoding;
    }
    return
$this->options['char_encoding'];
  }
// function char_encoding
?>

That should be:

<?php
 
function char_encoding($char_encoding = NULL) {
    if (
$char_encoding !== NULL) { // Error corrected
     
$this->options['char_encoding'] = $char_encoding;
    }
    return
$this->options['char_encoding'];
  }
// function char_encoding
?>

With both changes, accents should be not a problem for textile.module anymore.

#2

Tommy Sundstrom - February 6, 2005 - 23:24

Here's a patch of textile.module to fix the problem with accented characters.

Use together with the patch of Textile.php

AttachmentSize
textile.module 14.96 KB

#3

Tommy Sundstrom - February 6, 2005 - 23:26

Here is a patch of Textile.php to fix accented chars

Use together with the patch of textile.module

AttachmentSize
Textile.php 145.21 KB

#4

Tommy Sundstrom - February 6, 2005 - 23:28

SORRY included the full files not the patches.

Here we go again.

AttachmentSize
textile.module_1.patch 1.21 KB

#5

Tommy Sundstrom - February 6, 2005 - 23:29

and the other patch

AttachmentSize
Textile.php.patch 2.87 KB

#6

jhriggs - March 21, 2005 - 16:32
Assigned to:Anonymous» jhriggs

There were two things going on here. First, the module did not specify utf-8 as the charset for the Textile class. Second, there was a bug in TextilePHP that caused it to ignore false values for char_encoding. This is all addressed in the latest files in CVS. The lastest version for both 4.5 and 4.6 should work properly.

#7

Anonymous - April 4, 2005 - 17:15
 
 

Drupal is a registered trademark of Dries Buytaert.