[wp-trac] Re: [WordPress Trac] #3670: Removing CDATA close tag ( ]]> ) unbalances the CDATA block

WordPress Trac wp-trac at lists.automattic.com
Mon Feb 12 07:19:47 GMT 2007


#3670: Removing CDATA close tag ( ]]> ) unbalances the CDATA block
----------------------------+-----------------------------------------------
 Reporter:  scenic          |        Owner:  anonymous
     Type:  defect          |       Status:  new      
 Priority:  low             |    Milestone:  2.1.1    
Component:  Administration  |      Version:  2.1      
 Severity:  normal          |   Resolution:           
 Keywords:  dev-feedback    |  
----------------------------+-----------------------------------------------
Changes (by andy):

  * keywords:  => dev-feedback

Comment:

 Checking is_feed does not get to the root of the problem, which is that we
 are trying to nest CDATA sections where we should not. I don't know enough
 about XML but I think we ought to stop using CDATA markers in feed
 templates and use a function that can intelligently wrap any content in
 CDATA as needed, removing any nested markers.

 Is there really any reason to encode them rather than simply remove them?

 So what I propose, and what should be seen by somebody with XML chops, is
 this unintelligent function:

 function wp_cdata($data) {
  // Maybe test for conditions necessitating
  // CDATA markers and return if no need

  $data = str_replace('<![CDATA[', '', $data);
  $data = str_replace(']]>', '', $data);

  // Sometimes a trailing square bracket
  // can mess up XML parsers:
  if ( substr($data, -1) == ']' )
   $data .= ' ';

  return "<![CDATA[$data]]>';
 }

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


More information about the wp-trac mailing list