Leading space is removed from lines of code

dgrant - July 30, 2006 - 06:51
Project:Code Filter
Version:5.x-1.x-dev
Component:User interface
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

See the diff output here:

http://www.davidgrant.ca/digg_43things_and_drupal_via_xml_rpc

The codefilter is removing the first space of every line, and that screws up the indentation... This is what it looks like on my site, (I used the pre tag here)

--- blogapi.module.orig 2006-07-30 00:43:52.000000000 -0400
+++ blogapi.module      2006-07-30 02:41:20.000000000 -0400
@@ -191,6 +191,7 @@
  }
  $edit = array();
+  $blogid = 'story';
  $edit['type'] = _blogapi_blogid($blogid);
  // get the node type defaults
  $node_type_default = variable_get('node_options_'. $edit['type'], array('status', 'promote'));

It looks even weirder on drupal.org (using code tag):

--- blogapi.module.orig 2006-07-30 00:43:52.000000000 -0400
+++ blogapi.module      2006-07-30 02:41:20.000000000 -0400
@@ -191,6 +191,7 @@
   }

   $edit = array();
+  $blogid = 'story';
   $edit['type'] = _blogapi_blogid($blogid);
   // get the node type defaults
   $node_type_default = variable_get('node_options_'. $edit['type'], array('status', 'promote'));

#1

JohnAlbin - August 17, 2007 - 21:56
Status:active» postponed (maintainer needs more info)

Perhaps this has been fixed? Your second example looks totally fine to me.

#2

JohnAlbin - December 4, 2007 - 22:31
Title:Removing spaces» Leading space is removed from lines of code
Version:4.7.x-1.x-dev» 5.x-1.x-dev
Status:postponed (maintainer needs more info)» active

I've now been bitten by this bug while editing Drupal documentation.

#3

JohnAlbin - December 5, 2007 - 21:23

Specifically, the leading spaces in comments are not converted to   like the leading spaces in PHP code are.

#4

John Morahan - March 23, 2008 - 22:06
Status:active» needs review

Even more specifically, codefilter appears to be converting  's to spaces. It correctly avoids doing this when two of them appear together, but does not avoid doing it when a single   appears at the beginning of a line. Witness:

There is no space at the beginning of this line.
There is one space at the beginning of this line.
  There are two spaces at the beginning of this line.

AttachmentSize
codefilter_fix_spaces.patch 336 bytes

#5

John Morahan - March 24, 2008 - 16:14

Hmm, that didn't quite get them all.

AttachmentSize
codefilter_fix_spaces.patch 393 bytes

#6

cs8c - April 15, 2008 - 02:50

John Morahan - Your patch really corrected a major problem, thanks! I was about to give up on pasting code because it was just not showing up right until now, I needed to disable the filter and then re-enable it to show the changes though.

#7

John Morahan - April 15, 2008 - 12:25

That's to be expected, as filter output is cached; running update.php should also work.

#8

q0rban - November 10, 2009 - 14:01

I've got this problem as well inside <?php tags. It's even doing it on drupal.org, as you can see below:

<?php
/**
* This docblock gets it's leading spaces stripped.
* Each of these lines should have one space in front.
*/

  /**
   * However, if I put more than one space in there, it works fine.
   */
?>

 
 

Drupal is a registered trademark of Dries Buytaert.