Special characters in title don't render/display properly

Steps to reproduce the bug :

1. Create new article (node/add/article).
2. Enter Title with special characters like : You Know You’
3. Now Save.
4.Check Output of the created article for me output is same as Input You Know You’

I expect that drupal need to handle or decode the title field content.

For example:
1. If we use "â" then it should be "â".
2. If my title is You Know You’ then output/create title should be You Know You’

I fix this by using "decode_entities" on node validation before a node title is created or updated.

Is this right approach to fix this type of issue.??

Here, I want to know how drupal deal with special characters for title field.

Thanks
Kumar Rahul Sankrit

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rahul_sankrit created an issue. See original summary.

anurag.s’s picture

MegaChriz’s picture

Status: Active » Closed (works as designed)

This is not a bug. The title field is a plain text field, not a HTML field. Therefore anything you put in the title field will be taken literally.

virajrajankar’s picture

Assigned: Unassigned » virajrajankar
virajrajankar’s picture

Status: Closed (works as designed) » Needs review

You can use this function drupal_html_to_text($string, $allowed_tags = NULL) to remove special character from any string.

You will get the output of You Know You’ to "You Know You’".

You need to write hook_node_presave in your custom module to use "drupal_html_to_text()".


Example Code :

Create custom module and put below code.

function Mymodule_node_presave($node){  
  $node->title = drupal_html_to_text($node->title);
}
rahul_sankrit’s picture

Assigned: virajrajankar » rahul_sankrit
Status: Needs review » Fixed

This issue has been fixed so now i am closing.

Place this one:

function Mymodule_node_presave($node){  
  $node->title = drupal_html_to_text($node->title);
}

Thank you all.

rahul_sankrit’s picture

Status: Fixed » Closed (fixed)
MegaChriz’s picture

Category: Bug report » Support request