The attached patch adds an 'e' modifier to the regular expression so that the replacement can be evaluated as PHP code. The patch also includes the last parameter for the hook_filter and changes a double-quote to a single quote in the filter operations.

Comments

sillygwailo’s picture

StatusFileSize
new1.06 KB
fgm’s picture

Status: Active » Needs work

Needs to be converted to the "new" format no longer depending on invalid UTF8 sequences.

See #267484: Incorrect filter documentation for details.

sillygwailo’s picture

Assigned: Unassigned » sillygwailo
fgm’s picture

It probably means something like this:

     case 'prepare':
-      // Note: we use the bytes 0xFE and 0xFF to replace < > during the filtering process.
-      // These bytes are not valid in UTF-8 data and thus least likely to cause problems.
-      $text = preg_replace('@<dfn>(.+?)</dfn>@s', "\xFEdfn\xFF\\1\xFE/dfn\xFF", $text);
+      $text = preg_replace('@<dfn>(.+?)</dfn>@s', "[g2-dfn]\\1[/g2-dfn]", $text);
       return $text;
 
     case "process":
-      $text = preg_replace('@\xFEdfn\xFF(.+?)\xFE/dfn\xFF@se', "_g2_filter_process('$1')", $text);
+      $text = preg_replace('@\[g2-dfn\](.+?)\[/g2-dfn\]@se', "_g2_filter_process('$1')", $text);
       return $text;
 

Or maybe a simpler form in just one step, without prepare. The process callback seems to be unavoidable, though.

sillygwailo’s picture

Attaching a patch. Includes modification of the comments to reflect current practice.

sillygwailo’s picture

Status: Needs work » Needs review
fgm’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. I've included it in the dev. version (off-CVS for now).

fgm’s picture

Status: Reviewed & tested by the community » Fixed

Included in today's release, with a zillion other changes.

Status: Fixed » Closed (fixed)

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