use FilterInterface::prepare() to escape things

Created on 6 August 2023, 11 months ago
Updated 8 August 2023, 11 months ago

Problem/Motivation

It looks like we should use this to escape things like line breaks and PHP tags and so on.

I think πŸ› Blank lines in code get turned into P tags by filter_autop filter Active might be fixed by this?

This might also mean we reverse the recommended order of codefilter and HTML filter.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Support

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @joachim
  • πŸ‡¬πŸ‡§United Kingdom joachim
  • πŸ‡¬πŸ‡§United Kingdom joachim

    Actually, looking at version 7 of this module, this is how it should have been all along since D8, and it's probably broken because of this.

    D7 code has this:

        'prepare callback' => '_codefilter_prepare',
        'process callback' => '_codefilter_process',
    

    where the prepare callback is:

    > prepare callback: The name of a function that escapes the content before the actual filtering happens. See callback_filter_prepare() for details.

    So all this code:

    function _codefilter_prepare($text, $format) {
      $callback_prefix = $format->settings['codefilter_prism'] ? '_codefilter_prism' : '_codefilter';
      $text = preg_replace_callback('@<code([^>]*)>(.+?)

    @s', "{$callback_prefix}_escape_code_tag_callback", $text);
    $text = preg_replace_callback('@[\[<](\?php)(.+?)(\?)[\]>]@s', "{$callback_prefix}_escape_php_tag_callback", $text);
    return $text;
    }

    Should be in prepare().

    And all the code and comments that currently escape things only to un-escape them a few lines later will make more sense, because at the moment they seem pointless!!!

  • πŸ‡ΊπŸ‡ΈUnited States TolstoyDotCom L.A.

    At least on D10, CodeFilter extends FilterBase and FilterBase::prepare() simply returns its text argument without any processing.

  • Assigned to joachim
  • πŸ‡¬πŸ‡§United Kingdom joachim

    Yup.

    Working on this now -- this was a mistake made when converting the hook code to a plugin. Fixing this fixes various problems.

    • joachim β†’ committed 4b25e8cd on 2.0.x
      Issue #3379538: Fixed escaping not being done in FilterInterface::...
  • Status changed to Fixed 11 months ago
  • πŸ‡¬πŸ‡§United Kingdom joachim
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024