bug-ed
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-ed] Trailing spaces in filenames


From: Gabriel Farrell
Subject: Re: [Bug-ed] Trailing spaces in filenames
Date: Thu, 11 Dec 2014 16:06:02 +0000

Oops, I left the files in the wrong place when I made that patch. Here's one that should apply cleanly against 1.10:

--- main_loop.c 2014-12-11 10:56:24.745056389 -0500
+++ main_loop.c.new     2014-12-11 10:52:15.309058541 -0500
@@ -184,7 +184,8 @@
     { set_error_msg( "No current filename" ); return 0; }
   if( !resize_buffer( &buf, &bufsz, pmax + 1 ) ) return 0;
   for( n = 0; **ibufpp != '\n'; ++n, ++*ibufpp ) buf[n] = **ibufpp;
-  buf[n] = 0;
+  while( isspace( buf[--n] ) );                  /* drop trailing space */
+  buf[++n] = 0;
   while( **ibufpp == '\n' ) ++*ibufpp;                 /* skip newline */
   return ( may_access_filename( buf ) ? buf : 0 );
   }


On Thu Dec 11 2014 at 4:32:49 AM Gabriel Farrell <address@hidden> wrote:
I've noticed that trailing spaces are not ignored when a filename is input. For example:

    $ touch a.txt
    $ ed
    e a.txt <------------------- trailing space here
    a.txt : No such file or directory
    ?

This has become an annoyance because I'm often wrapping ed in rlfe, which appends a space to the filename upon tab completion. The following patch ignores trailing space without breaking any tests. I considered adding a test to confirm the new behavior but couldn't figure out the testsuite. :) Feedback on the patch would be appreciated -- I have little experience in C programming.

--- main_loop.c-orig    2014-12-11 02:44:53.239668678 -0500
+++ main_loop.c 2014-12-11 04:22:23.826563905 -0500
@@ -184,7 +184,8 @@
     { set_error_msg( "No current filename" ); return 0; }
   if( !resize_buffer( &buf, &bufsz, pmax + 1 ) ) return 0;
   for( n = 0; **ibufpp != '\n'; ++n, ++*ibufpp ) buf[n] = **ibufpp;
-  buf[n] = 0;
+  while( isspace( buf[--n] ) );                  /* drop trailing space */
+  buf[++n] = 0;
   while( **ibufpp == '\n' ) ++*ibufpp;                 /* skip newline */
   return ( may_access_filename( buf ) ? buf : 0 );
   }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]