A piece of code like $object->property desn't get properly encoded, resulting in a piece of code with html entities : $object->property.

$object->property

gives

$object->property

once highlighted

Comments

Johann Wagner’s picture

StatusFileSize
new508 bytes

A patch to correct this bug :

soxofaan’s picture

Status: Active » Needs review

what other filters are there in the text format and in what order?

Status: Needs review » Needs work

The last submitted patch, geshifilter-htmlentity_decode-2047021-1.diff, failed testing.

askibinski’s picture

Issue summary: View changes

This is an issue using CKEditor + CodeSnippet plugin, because html is turned into entities and should be decoded, BUT only for the code between code tags. I tried with something like this which works for most cases, but not when the itself contains pre and code tags.

/**
 * Prepare callback for the GeSHi filter.
 */
function geshifilter_prepare_callback($text, $filter) {
  // When using geshifilter together with ckeditor+codesnippet, html entities will get encoded.
  // We need to decode those, but only the string between <code> tags.
  if (preg_match_all('/<code.*?>(.*?)<\/code>/s', $text, $matches)) {
    if (is_array($matches[1])) {
      foreach ($matches[1] as $old_string) {
        $new_string = htmlspecialchars_decode($old_string);
        $text = str_replace($old_string, $new_string, $text);
      }
    }
  }
  require_once drupal_get_path('module', 'geshifilter') .'/geshifilter.pages.inc';
  return _geshifilter_prepare($filter->format, $text);
}
yukare’s picture

On my site i use this, quoted from a site, just i do not have the url now:

You must hack a GeSHi filter file. I'm talking about the code you download separately form the Drupal GeSHi module.

Under sites/[sitename or all]/modules/geshifilter/geshi, open geshi.php for editing. Add the below code at line 2046 (a blank line in GeSHi 1.0.8.6) or after // Replace all newlines to a common form:

// Replace all newlines to a common form.

$code = str_replace("&gt;", ">", $code);
$code = str_replace("&lt;", "<", $code);
$code = str_replace("&amp;", "&", $code);
$code = str_replace("&#39;", "'", $code);
$code = str_replace("&quot;", """, $code);

I have seen that this will be a bigger issue in drupal 8 , as it will use ckeditor by default.
I will work on a fix for drupal 8 this week, have started it already, and it maybe simple as this: on filter prepare call a "decode" function only with the contents that will be passed to geshi(so do not need a regex for all possible blocks) and do the above changes on it. I am 99% sure that the same code used on drupal 8 will work on drupal 7.

yrocq’s picture

Hi ! I also have this problem for one if my projects. I think replacing the entities is a good idea, but it may not be appropriate in all cases. I suggest that we add it as a setting. Here is my patch.

yukare’s picture

I like this patch, and as a setting it will not change as it works now, which is good, but this part:

  // Decode HTML entities if option has been set
  if (geshifilter_decode_entities()) {
   $text = html_entity_decode($text, ENT_QUOTES);
}

Must be moved to latter in processing, maybe to geshifilter_process_sourcecode(), or somewhere before it with $format available, because now it will work on all text, not only in text that geshi will process.

  • yukare committed a8817bd on
    Issue #2047021 by yukare, yrocq: Special chars are html entities in...
yukare’s picture

The previous commit was for Drupal 8, please use it as a base for a Drupal 7 patch.

yrocq’s picture

I changed my patch so that the decoding is made in geshifilter_process_sourcecode. I wanted to add tests, but they are currently broken for the Drupal 7 version of this module. I can submit a more complete patch when this issue will be resolved.

yukare’s picture

Tests are working now, they are fixed and all tests are passing since per filter settings are fixed too. I just would like to have it enabled on d.o but it do not work here because geshi library will be missing.

yukare’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new4.31 KB

This patch add tests and move the decode to prepare functions, where we have $format available. Please review it.

Working on this make me love the new oop from Drupal 8 where we do not need to pass $filter or $format around.

ar-jan’s picture

The patch in #12 applies and works in my testing (special characters are rendered correctly in highlighted code). If there are no objections code-wise I'd say RTBC.

MulleG’s picture

Status: Needs review » Reviewed & tested by the community

Patch #12 also works for me

Morten

crzdev’s picture

Thanks yukare, path #12 working perfectly!

mausolos’s picture

Also tested #12, works great! Was tearing my hair out! So this patch has been out there now for TWO YEARS. When can we get this rolled into the official module? Anything I can do to make that happen faster?

Thanks!
Charles

  • yukare authored 3e92826 on 7.x-1.x
    Issue #2047021 by yrocq, yukare, Johann Wagner: Special chars are html...
yukare’s picture

Status: Reviewed & tested by the community » Fixed

Commited, thanks everyone.

Status: Fixed » Closed (fixed)

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