Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Parse an URL

by Anonymous Monk
on Apr 09, 2002 at 06:56 UTC ( [id://157668]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Parse an URL
by rjray (Chaplain) on Apr 09, 2002 at 07:16 UTC

    I'm afraid that the first thing you need to do is find a JavaScript forum to take your problem to. This is a Perl forum, and I can't help but suspect that those who reply after me won't be quite as polite.

    That having been said, if you come to the realization that you're better-off doing the sanity check in a cleaner language, and simply re-painting the form with badly-formed fields noted (red is usually a good color for this sort of thing) while carrying over the valid form fields as "sticky" values, then you will have the luxury of using URI, which is a very clean, easy-to-use module that should handle more URI issues than you're likely to throw at it.

    --rjray

Re: Parse an URL
by grinder (Bishop) on Apr 09, 2002 at 07:31 UTC

    rjray speaks wisely. The only thing I would add is that all your funky javascript code will be for nought, should the user happen to have javascript deactivated.

    A second possibility is that someone will pick apart your form and figure out what values the server is looking for, and craft their own response, completely bypassing the validations the javascript code performs.

    Never, ever trust anything coming from the client. Buried in a recent thread on web site design (or lack thereof) are some pointers to some very good sources of information that it would behoove you to read.


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
Re: Parse an URL
by tachyon (Chancellor) on Apr 09, 2002 at 12:15 UTC

    You will have to do your own work and learn about pattern matching regexes then read the relevant RFCs to determine what constitutes a valid URL. This snippet basically shows you how you do it but the only valid URL is http://perlmonks.org

    <head> <script> function check(url) { if (url.match("(http|ftp)://perlmonks.org") ) { return 1; } else { alert(url+" is not a valid URL\nPlease enter a valid one") my_form.url.value = 'http://'; return 0; } } function check_fields(form) { // check your form fields here alert("You need to revalidate server side! use Perl;"); return 1; } </script> </head> <body> <form name="my_form" method=GET action="/do/this/stuff.cgi" onSubmit=" +check_fields(my_form)"> <p><input type="text" name="url" size=25 maxlength=100 value="http://" + onMouseOut="check(url.value)"> <p><input type="submit" value="Stumbit"> </form> </body> </html>

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      There is an excellent perl module for URI-parsing. Imho having everyone invent his own URL-parser is unnecessary work. You might take a look at: http://search.cpan.org/~gaas/URI-1.40/URI/Split.pm

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://157668]
Approved by strat
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-18 04:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found