Skip Menu |

This queue is for tickets about the File-Remove CPAN distribution.

Report information
The Basics
Id: 11820
Status: resolved
Priority: 0/
Queue: File-Remove

People
Owner: Nobody in particular
Requestors: smylers [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.29
Fixed in: (no value)



Subject: Paths with Spaces Need Quoting
Hello there. Thank you for maintaining File::Remove -- we're finding it convenient for removing files that match a particular glob in a cross-platform way. However there is something we've just been tripped up by, and I thought it's probably worth a little attention. Another affect of the wildcard expansion provided by the glob function is that spaces are used to delimit patterns, like at a Unix command line. This means that if the path has a space in it (for example 'C:/Program Files/OurApp/data/*.txt') then it will erroneously be treated as multiple paths. One quick fix would be to explicitly document this behaviour, telling users to use backslashes or quote marks to protect the spaces. However that would be less than idea: unlike at a Unix shell, where a space has to be an argument separator, File::Remove::remove takes a Perl list of filenames, and there is no reason for somebody specify multiple paths in a single string: if they want to split on spaces they can use qw (like you do in the docs) or split or whatever. So you could just put a backslash before each space in the input. The only downside with that, is that it would break for anybody who's already working round this behaviour by putting a backslashes in there (though strangely, not anybody who's using quotemarks -- if you use both, it still works fine), but this has a chance of working: s/(?<!\\) /\\ /g I think that will fail for anybody who hasn't backslashed their spaces but does have a genuine backslash in a pathname just before a space. But spaces are most common in paths on Windows, where backslash can't be included in a filename component anyway, because it's the path separator, and you're very unlikely to get a filename starting with a space? And since the code isn't working for such people at the moment, implementing the above wouldn't make things any worse for people. Best wishes. Smylers
Do you have an example usage that demonstrates the problem but should work? I think I understand the request, but I'd like to have code to be sure.
I've added a test script for this case, and it returns success. Marking as resolve until someone can update with a specific failing case