autoconf-patches
[Top][All Lists]
Advanced

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

Re: [PATCH 1/10] Proper file name escaping in Autoconf programs and Perl


From: Paul Eggert
Subject: Re: [PATCH 1/10] Proper file name escaping in Autoconf programs and Perl modules.
Date: Tue, 04 Dec 2007 15:12:02 -0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Ralf Wildenhues <address@hidden> writes:

> +# $FILE_NAME
> +# shell_quote ($FILE_NAME)
> +# ------------------------
> +# If the string $S is a well-behaved file name, simply return it.
> +# If it contains white space, quotes, etc., quote it, and return
> +# the new string.
> +sub shell_quote($)
> +{
> +  my ($s) = @_;
> +  if ($s =~ m![^\w+/.,-]!)
> +    {
> +      # Convert each single quote to '\''
> +      $s =~ s/\'/\'\\\'\'/g;
> +      # Then single quote the string.
> +      $s = "'$s'";
> +    }
> +  return $s;
> +}

A nit: if the goal is to quote only those file names requiring
quoting, then this quotes too often; e.g., it quotes @ in file names.
I think the only characters you should need to worry about in practice
are:

\t \n \r space ! " # $ % & ' ( ) * ; < > ? [ \ ^ ` | ~




reply via email to

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