Evaluate the replacement as PHP code, bring G2 hook_filter implementation up to speed with Drupal 6

Richard Eriksson - September 17, 2009 - 18:31
Project:G2 Glossary
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Richard Eriksson
Status:closed
Description

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.

#1

Richard Eriksson - September 17, 2009 - 18:32
AttachmentSize
580576-evaluate-replacement.patch 1.06 KB

#2

fgm - October 27, 2009 - 18:09
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.

#3

Richard Eriksson - October 27, 2009 - 23:50
Assigned to:Anonymous» Richard Eriksson

#4

fgm - October 28, 2009 - 07:05

It probably means something like this:

<?php
    
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.

#5

Richard Eriksson - October 28, 2009 - 17:45

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

AttachmentSize
580576-evaluate-replacement-plus-placeholders.patch.txt 1.42 KB

#6

Richard Eriksson - October 28, 2009 - 17:46
Status:needs work» needs review

#7

fgm - October 29, 2009 - 09:03
Status:needs review» reviewed & tested by the community

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

#8

fgm - November 11, 2009 - 21:43
Status:reviewed & tested by the community» fixed

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

#9

System Message - November 25, 2009 - 21:50
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.