PHP 5.3 introduced namespaces. Drupal 8 will make use of them. Code samples are starting to appear on Drupal.org that include namespace syntax.

CodeFilter chokes on namespace syntax. Specifically, backspaces are simply stripped.

This is not a good situation.

See for example here: http://drupal.org/node/1292720 Under the "getting a context object" section.

The line "use \Drupal\Context\Context" is rendered as "use DrupalContextContext", which is, er, wrong.

I am marking this major as it relates to Drupal.org documentation.

CommentFileSizeAuthor
#2 codefilter.test.2.patch6.5 KBsun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Crell’s picture

Priority: Major » Critical

Bumping to critical, since we're posting more and more namespace-using code into issues and docs pages so this is becoming a larger and larger issue. :-(

sun’s picture

Status: Active » Needs review
FileSize
6.5 KB

I'm not able to reproduce this issue in the latest D7 code.

Attached patch adds the first test for Code Filter. (Also added a web test template, but currently unused, please ignore.)

webchick’s picture

Ha. Funny story. TRUE story. :)

This is not a bug in this module at all.

This problem is coming from the http://ca3.php.net/highlight_string function.

This script:


$php = '
<?php use Drupal\Core\Database\Query\AlterableInterface;
';

echo highlight_string($php);

When run in PHP 5.3 returns:

<?php use Drupal\Core\Database\Query\AlterableInterface; ?>

But when run in PHP 5.2 (Drupal.org is running PHP Version 5.2.17) returns:

<?php use DrupalCoreDatabaseQueryAlterableInterface; ?>

I guess it makes sense. Namespaces are a PHP 5.3+ thing.

So the solution is either to write our own version of highlight_string() for PHP 5.2 that interprets namespaces correctly, or upgrade Drupal.org to PHP 5.3.

webchick’s picture

Inquiring about the latter over at #1481162: Update prod to PHP 5.3.

Crell’s picture

Priority: Critical » Minor

Oh D'Oh! That's awesome. :-)

I guess this isn't critical then, as the fix is to fix Drupal.org.

Leaving open anyway for now since it's linked from a few places.

cweagans’s picture

Status: Needs review » Fixed

This is working on d.o now, since #1481162: Update prod to PHP 5.3 is done, so can we call this fixed?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.