[19707] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1902 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 10 03:10:30 2001

Date: Wed, 10 Oct 2001 00:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1002697813-v10-i1902@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 10 Oct 2001     Volume: 10 Number: 1902

Today's topics:
    Re: Special Pattern Match (Ian Boreham)
    Re: Special Pattern Match (Ian Boreham)
    Re: Special Pattern Match <Laocoon@eudoramail.com>
    Re: Special Pattern Match <Laocoon@eudoramail.com>
    Re: Stop Transversal of a Directory with Tar and Unzip <goldbb2@earthlink.net>
    Re: Stop Transversal of a Directory... the dot dot prob <lpitcher@sympatico.ca>
        string literal vs. string variable problem... <ted_godwin@mindspring.com>
    Re: Upload file with Netscape 4.6 (David Efflandt)
    Re: use strict my $foo = "";  Bug? (Greg Bacon)
    Re: using s/// (John J. Trammell)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 9 Oct 2001 18:53:28 -0700
From: ianb@ot.com.au (Ian Boreham)
Subject: Re: Special Pattern Match
Message-Id: <f02c4576.0110091753.539d3ffb@posting.google.com>

Laocoon <Laocoon@eudoramail.com> wrote in message news:<Xns9135B816E65FBLaocooneudoramailcom@62.153.159.134>...

>Jean-Philippe Fauvelle <JPFauvelle@Colt-Telecom.fr> wrote in
>news:hm76stc8sdrsgkan9q98tsvtaf21gte51v@4ax.com: 
>> Le Tue, 9 Oct 2001 15:41:00 GMT, JHM1MAO@leeds.ac.uk (M.A. Oxby)
>> écrit: 
>> 
>> if ( $str =~ m#^(?:http://|mailto:)\S+$# ) {
>This does not make sure that its not surrounded by double quotes.

Well, technically it does. It makes sure it starts with "h" or "m", so
it can't be "surrounded by quotes". It might end with one, though. The
original question was too vague to write a definitive regex.

Regards,


Ian


------------------------------

Date: 9 Oct 2001 19:05:41 -0700
From: ianb@ot.com.au (Ian Boreham)
Subject: Re: Special Pattern Match
Message-Id: <f02c4576.0110091805.432d6c74@posting.google.com>

Laocoon <Laocoon@eudoramail.com> wrote in message news:<Xns9135B7D6ED7CCLaocooneudoramailcom@62.153.159.134>...

>JHM1MAO@leeds.ac.uk (M.A. Oxby) wrote in news:GKy3Gr.HpH@leeds.ac.uk:
>> I might be asking a bit much here, but I need a special pattern 
>> match/substitution and I can't figure it out. I need to match a
string
>> that: 
>> 
>> 1. Is NOT surrounded by " " s
>> 2. Begins with http:// or mailto:

The question as stated is too vague. It doesn't say whether it is
trying to match it within a larger string, or as a whole string.

>$string =~ m#^[^"]*(?:http://|mailto:)[^"]+$#;

This allows any number of non-quote characters at the start. That is
not consistent with [2] if we are doing an exact match. If you are
assuming it is in the context of a larger string, then you are going
to lose matches in which there are quotes anywhere beforehand in the
string. In this case, you should use a negative look-behind.

This regex also forces the existence of a non-quote character after
the prefix, which was not in the specification (although I imagine it
probably should have been).

It also disallows quotes anywhere in the trailing portion. Since
e-mail addresses can contain quotes, that may not be valid either.

The question should include a specification of what characters are
allowed in the trailing portion. A description of the need for the
match would probably help too. My quess is that the OP wants to match
URLs in some text and substitute HTML links.

Regards,


Ian


------------------------------

Date: Wed, 10 Oct 2001 06:45:23 +0200
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Special Pattern Match
Message-Id: <Xns913644BB61D36Laocooneudoramailcom@62.153.159.134>

ianb@ot.com.au (Ian Boreham) wrote in
news:f02c4576.0110091805.432d6c74@posting.google.com: 

> Laocoon <Laocoon@eudoramail.com> wrote in message
> news:<Xns9135B7D6ED7CCLaocooneudoramailcom@62.153.159.134>... 
> 
>>JHM1MAO@leeds.ac.uk (M.A. Oxby) wrote in news:GKy3Gr.HpH@leeds.ac.uk:
>>> I might be asking a bit much here, but I need a special pattern 
>>> match/substitution and I can't figure it out. I need to match a
>>> string that: 
>>> 
>>> 1. Is NOT surrounded by " " s 2. Begins with http:// or mailto:
> 
> The question as stated is too vague. It doesn't say whether it is
> trying to match it within a larger string, or as a whole string.
> 
>>$string =~ m#^[^"]*(?:http://|mailto:)[^"]+$#;
> 
> This allows any number of non-quote characters at the start. That is
> not consistent with [2] if we are doing an exact match. If you are
> assuming it is in the context of a larger string, then you are going
> to lose matches in which there are quotes anywhere beforehand in the
> string. In this case, you should use a negative look-behind.

It will match _none_ or more of non-quote characters which means it can 
match at the beginning of a line or in the middle of a string..
But i agree that a negative look-behind woulda been better
 
> This regex also forces the existence of a non-quote character after
> the prefix, which was not in the specification (although I imagine it
> probably should have been).

I assumed that an url/email always follows..

 
> It also disallows quotes anywhere in the trailing portion. Since
> e-mail addresses can contain quotes, that may not be valid either.

I didn't know that..thx for telling me.. 
though i do not think its often used :)
 
> The question should include a specification of what characters are
> allowed in the trailing portion. A description of the need for the
> match would probably help too. My quess is that the OP wants to match
> URLs in some text and substitute HTML links.
> 
> Regards,
> 
> 
> Ian

Lao 


------------------------------

Date: Wed, 10 Oct 2001 06:46:58 +0200
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Special Pattern Match
Message-Id: <Xns9136450038014Laocooneudoramailcom@62.153.159.134>

>>> if ( $str =~ m#^(?:http://|mailto:)\S+$# ) {
>>This does not make sure that its not surrounded by double quotes.
> 
> Well, technically it does. It makes sure it starts with "h" or "m", so
> it can't be "surrounded by quotes". It might end with one, though. The
> original question was too vague to write a definitive regex.

my mistake
 

Lao


------------------------------

Date: Wed, 10 Oct 2001 00:17:20 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Stop Transversal of a Directory with Tar and Unzip
Message-Id: <3BC3CBD0.3993ACD8@earthlink.net>

What A Man ! wrote:
[snip]
> I have used Archive::Tar successfully before, but not Archive::Zip.
> Since, WinZip and PKZip are based on GNU's "unzip", I just assumed
> "unzip" was the better program to use.

Actually, I think PKZip was first, then the others.

> After viewing Archive::Zip docs, I can see that it offers more
> options. I wouldn't mind seeing how you would handle the ".." and "~"
> problem using Archive::Tar either.

Umm, about the same way?
Ok, the names of the methods would be different, bit it wouldn't be all
that different.

> > Here's some [untested] solutions for doing what you're asking for:
> > unzip file.zip -x "../*" -x "*/../*" -x "/*" -x "~*" -d wkdir
> I've previously tried the -x switch with unzip. I've been using it
> with only one -x, such as -x ".." "~"; but it doesn't appear to work
> half the time. Also, won't ".." and "~" cover all of the files that I
> need to exclude?

Well, I dunno about whether using one -x would work [or even if it
should], but you definitely can't just use ".." and "~", since -x
requires a glob of files, not just string to check for being a
substring.  As a glob, ".." matches exactly one file, one whose name is
".."; likewise, "~" will only match a file whose name is "~".

Depending on how unzip's globbing works, you might be able to put your
list of globs into a single space-seperated list, passed as a single
argument to -x... for example, the following *might* work:

    unzip file.zip -x "../* */../* /* ~* */~*" -d wkdir

[This is untested].  And the reason I don't just use "*..* *~*" as my
exclude list is that there seems to be no reason to exclude files whose
names are like "tildes~are~fun" or "aargh...I...hate...elipsis"

> > tar xf file.tar --exclude="../*" --exclude="*/../*" \
> >     --exclude="/*" --exclude="~*" -C wkdir
> I've used the --exclude switch before also, but couldn't get it to
> work.
> I must've got the syntax wrong. I'll try it again. See below.
> 
> > However, I would like to point out that --exclude probably only
> > exists with GNU tar, and thus is not likely to be portable.
> >
> > I also don't know if more than one exclude glob is allowed... the
> > docs don't say one way or another.  Having more than one might not
> > work, and probably isn't portable even if it does work.
> 
> Good information. Thanks.
> 
> > I don't have a non-gnu tar, but it's possible that the -X option
> > mentioned in the man page isn't a GNU specific option [this is a
> > guess based on the fact that it's a single letter flag]... if that's
> > so, then you could do:
> >
> > (for glob in "../*" "*/../*" "/*" "~*"; do
> >     echo "$glob"
> > done) > exclude.txt
> > tar xf file.tar -X exclude.txt -C wkdir
> 
> > *If* -X exists with older tars, then this might be portable, but
> > then again, it might not be.  And the exclude file might only allow
> > real file names, not globs... so that too might be a kind of
> > nonportability.
> 
> I believe my tar is GNU tar. Thanks for the glob script above. My
> understanding of the docs is that "-X file" or "--exclude-from=file"
> is the same, and it does the same as "--exclude=pattern", except
> patterns are not put in a separate file with "--exclude=pattern".

Yeah, which is why I did it as I did.  The reason I say that -X might be
portable, though, is that the GNU style of options is to have --foo=bar,
whereas pre-GNU programs usually do it as -F bar or somesuch, usually a
single letter flag.

I doubt that you'll have --foo=bar syntax on most non-gnu programs...

ObPerl: the Getopt and GetoptLong perl modules implement these two
styles of commandline argument parsing.

> I'd rather put all the exclusion patterns in the same file, as you've
> done in your glob example. So, do all of these exclusion methods only
> accept patterns, and not filenames?

Umm, I dunno.  Why not try it and find out?

> > If you used Archive::Tar, you would have much less to worry about
> > with regard to such portability problems... and it's probably easier
> > to convert a program which uses A::Z to one using A::T than it is to
> > convert a shell script which uses unzip to one using tar.
> >
> Point well taken. Archive::Tar and Archive::Zip allow more
> portability, more options, and are better to use than their GNU
> binaries in your opinion... and after reviewing their docs, I'd have
> to agree.

<grin> Isn't that the point of using perl? :)

-- 
    "Just how stupid are you Kuno?"
    "Verily, Tatewaki Kuno knows no limits."


------------------------------

Date: Tue, 09 Oct 2001 21:47:55 -0400
From: Lew Pitcher <lpitcher@sympatico.ca>
Subject: Re: Stop Transversal of a Directory... the dot dot problem
Message-Id: <3BC3A8CB.D748B7AE@sympatico.ca>

Bill Unruh wrote:
> 
> In <3BC10741.44644D5C@home.com> "What A Man !" <whataman@home.com> writes:
> 
> ]How can I stop directory transversal with perl? I want to list all of my
> ]files and directories off of a sub-directory named "wkdir". and delete
> ]any files or directories that begin with ".." or "~" (since the shell
> ]can expand a "~"). The purpose is to stop people from writing in my main
> ]directory or other directories; and only allow them to write in "wkdir".
> ]This is running on a FreeBSD server.
> 
> I think you are confused. .. is NOT a filename. It is a shorthand for the parent of
> the current directory.

I hate to correct you, Bill, but...

 .. is the name of a file; specifically, it's the name of a hardlink to
the file that contains the parent directory. However, since directories
are very special files, the regular file utils work differently on them.

> You canot delete it. If there are files which begin wit ..
> they are almost certainly invalid files, or cracker files.
> 
> ~ has nothing to do with filenames, it is expanded by the shell, not the
> filesystem, as the home directory. If a file exists with that name, then it is
> probably illegal.
> 
> rm ..?* will erase all files which begin with ..
> rm ./~?* will erase all files which begin with ~.
> (the ? means "match exactly one arbitrary character, meaning both of these must
> have at least one character more than just the .. or the ~)
> 
> ]After an extensive search of Google, here is what I have. I am doing
> ](print "$filename") first to see what I get in $filename. Later I will
> ]change (print "$filename") to unlink "$filename"; but print "$filename"
> ]is not working below as intended. It lists "." files such as .htaccess.,
> ]and subdirectories that don't even match my regex. Why?
> 
> because . in a regex matches any single character. ( as with the ? above for hte
> shell). \. matches the character of the single period. also your regex says look
> for ~ or .. anywhere in the filename, not at its beginning.
> 
> ]use File::Find;
> ]sub eachFile {
> ]  $filename = $_;
> ]  $fullpath = $File::Find::name;
> ]# remember that File::Find changes your CWD,
> ]#so you can call open with just $_
> ]if ($filename =~ "~|.." ) { print "$filename <BR>\n"; }
> ]}
> ]find (\&eachFile, "wkdir/");
> 
> ]Kind Regards,
> ]--Dennis

-- 
Lew Pitcher

Master Codewright and JOAT-in-training
Registered Linux User #112576


------------------------------

Date: Tue, 9 Oct 2001 21:43:30 -0400
From: "TedWeb" <ted_godwin@mindspring.com>
Subject: string literal vs. string variable problem...
Message-Id: <9q0986$qgj$1@slb7.atl.mindspring.net>

Hello everyone,

I've been translating an ASP VBScript file to PerlScript and have one
bizarre problem. The VBScript reads this:
file.SaveAs(fileName)

In PerlScript it reads:
$file.SaveAs($fileName);

The problem is that the Perl version won't accept a string variable.
However, if I typed:
$file.SaveAs('$fileName'); it would work, only using the incorrect literal
value. Any help?

Many thanks,
-Ted




------------------------------

Date: Wed, 10 Oct 2001 03:36:23 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Upload file with Netscape 4.6
Message-Id: <slrn9s7ghn.muq.efflandt@typhoon.xnet.com>

On Tue, 09 Oct 2001 16:25:21 +0800, Daping Wang <dapingwang@lucent.com> wrote:
> Hello,
> 
> Does anyone ever ran into the trouble with uploading in Netscape?

Have you checked to see if your HTML validates (I thought no).  I don't 
think 
<table><form></table></form> is valid HTML because the tags overlap.

Also the leading ./ in your action path is redundant when followed by ../, 
not that it does any harm, just that the ./ serves no function in this 
context.

> I have a html page with lines as
><form ENCTYPE="multipart/form-data" METHOD=POST
> action="./../cgi-bin/estimates.cgi">
><tr>
><td>Work Item:
><br><input TYPE=TEXT NAME="wi" SIZE=15 MAXLENGTH=20></td>
></tr>
> 
><tr>
><td>Estimation File:
><br><input TYPE="FILE" NAME="file" SIZE=15 MAXLENGHT=10000></td>
></tr>
> 
><tr>
><td><input TYPE=SUBMIT VALUE="Submit"><input TYPE=RESET VALUE="Reset"></td>
></tr>
></table>
> 
></form>
> 
> It works very well with IE4.0+ but failed with my netscape on Solaris.
> I am using CGI.pm to handle the filename. It happened that the return
> value from $query->upload was undef with my netscape. Is there any 
> clue to this problem?
> 
> Thanks,
> Daping Wang
> Lucent Technologies.


-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


------------------------------

Date: Wed, 10 Oct 2001 01:09:28 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: use strict my $foo = "";  Bug?
Message-Id: <ts77u8hfaedob1@corp.supernews.com>

In article <slrn9s6qlm.rdd.abigail@alexandra.xs4all.nl>,
    Abigail <abigail@foad.org> wrote:

: Do you know why the patch was never accepted?

Probably because I didn't really champion it.  Sometimes p5p reminds
me of driving the sled at football practice back in the day.  If you
don't push really hard, it'll turn on you. :-)

Greg
-- 
They say that politics is the art of compromise. And that's true. The
politicians compromise away our money, our civil liberties, and our
property.
    -- Harry Browne


------------------------------

Date: Tue, 9 Oct 2001 22:06:31 -0500
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: using s///
Message-Id: <slrn9s7epn.q7n.trammell@haqq.hypersloth.net>

On Tue, 09 Oct 2001 21:36:11 GMT, Paul Richardson wrote:
> I am trying to substitute a blank space for the string
> "/* unconnected */" (the target string is w/o quotes). I can
> eliminate the "* unconnected *" portion but can get rid of the
> slashes. I have searched my perl pbbok to no avail though it was late
> last night so who knows. Can someone give me some help. I am sure I'll
> go "doooohhhhh!!!" once I see the answer

 s[/\* unconnected \*/][]



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 1902
***************************************


home help back first fref pref prev next nref lref last post