Download & Extend

Leading space is removed from lines of code

Project:Code Filter
Version:6.x-1.x-dev
Component:User interface
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

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'));

Comments

#1

Status:active» postponed (maintainer needs more info)

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

#2

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

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

#4

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

Hmm, that didn't quite get them all.

AttachmentSize
codefilter_fix_spaces.patch 393 bytes

#6

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

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

#8

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.
   */
?>

#9

Version:5.x-1.x-dev» 6.x-1.x-dev

At the least, this is a problem with 6.x.

#10

The patch in #5 was not working for me. Here's a patch that does two preg_replace() calls instead for clarity.

I had to test against 6.x-1.0 as 6.x-1.x was causing PHP to segfault on my MAMP installation. As well, this patch can be cherry-picked to master, but I haven't tested that either.

AttachmentSize
76234.10-fix_leading_space.patch 0 bytes

#11

Whoops.

AttachmentSize
76234.11-fix_leading_space.patch 923 bytes
nobody click here