[wp-trac] Re: [WordPress Trac] #2059: Slashes stripped in <pre> (caused by #1793)

WordPress Trac wp-trac at lists.automattic.com
Fri Sep 7 17:53:22 GMT 2007


#2059: Slashes stripped in <pre> (caused by #1793)
------------------------------------+---------------------------------------
 Reporter:  allan                   |        Owner:  anonymous
     Type:  defect                  |       Status:  new      
 Priority:  normal                  |    Milestone:  2.3      
Component:  General                 |      Version:  1.5.2    
 Severity:  normal                  |   Resolution:           
 Keywords:  has-patch dev-feedback  |  
------------------------------------+---------------------------------------
Comment (by DelGurth):

 Replying to [comment:6 Albertane]:
 > What is the right approach?  I'd really like to get this fixed, it makes
 it a pain to try and post code snippets to my blog.  Does the attached
 patch still work on 2.2?  Is it going to cause other problems?  Thanks.
 [[BR]]
 The right approach would be something like (at least, this code seems to
 work for me):

 {{{
 $pee = preg_replace_callback('!(<pre.*?>)(.*?)</pre>!is',
 create_function('$matches', 'return $matches[1] . clean_pre($matches[2]) .
 "</pre>";'), $pee);
 }}}

 Replying to [comment:5 mdawaffe]:
 > Messing with stripslashes is the wrong approach.
 >
 > A good rule of thumb, never use preg_replace(/e); the slashing is too
 complicated.  Use preg_replace_callback() instead.

 It can be a good rule of thumb, but it was in there already. So why not
 use it? But true, it sounds like you can better use preg_replace_callback
 then just the /e variant, since you can trap yourself in some nice
 problems (see the PHP documentation about it(1)).
 [[BR]]
 But the stripslashes should not be needed in the first place. At least,
 according to me slashes should be allowed within a <pre> tag.

 [[BR]]
 [[BR]]
 I was personally wondering why the stripslashes was there in the first
 place. But I guess that has something to do with a PHP bug(2) I found when
 I was looking why I was loosing slashes in wordpress within my <pre> tags.

 (1) http://www.php.net/preg_replace [[BR]]
 (2) http://bugs.php.net/bug.php?id=10666

-- 
Ticket URL: <http://trac.wordpress.org/ticket/2059#comment:7>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list