Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Steps to reproduce:
$nid = // Some nid of a node that has a link with the title 'Foo & Bar' linked to 'http://example.com/'.
$node = node_load($nid);
debug($node->field_link);
node_view($node, 'full');
debug($node->field_link);
The first debug after node_load() will look like:
array (
'und' =>
array (
0 =>
array (
'url' => 'http://example.com/',
'title' => 'Foo & Bar',
'attributes' =>
array (
),
),
),
)
The second debug() after the call to node_view() results in:
array (
'und' =>
array (
0 =>
array (
'url' => ''http://example.com/',
'title' => 'Foo & Bar',
'attributes' =>
array (
),
'display_url' => 'http://example.com/',
'html' => true,
),
),
)
Notice the 'title' attribute has been escaped. Now if I'm trying to use this raw link data to output elsewhere, I'm screwed. The link module should *not* be altering field data on the node. If we were to call node_save() after this code, it would result in data loss as Foo & Bar
would be saved as the 'title' value in the field.