Peter Hoppe wrote:I am working on a web project and needed some test URLs to test a URL input validator for a web form. Sadly, I found no test data set of real world URLs. So I wrote a random URL generator which creates HTTP(S) links. I'd like the generator to create links which are valid so I can run my tests with those randomly generated URLs. For reference I delved into RFC1738 (ouch, 20 years old), even though I deviated slightly (e.g. I'm creating https urls which isn't mentioned in RFC1738). See below for the generator's source code. Could you kindly comment on the code?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Well, my first one is that it's rather long.
We're all volunteers here, and asking people to plough through over 400 lines of code, however nicely documented and formatted (and it certainly appears to be that), isn't likely to produce a lot of responses. Is there any way you could shorten it? - eg, perhaps only include the parts you think might be causing problems.
however nicely documented and formatted (and it certainly appears to be that)
Second: I'm not quite sure what a "random" URL generator will give you - even if it can spew out valid URLs for you - because unless the URL actually exists, you won't be able to connect to it. Perhaps you could explain how you intend to use it.
because unless the URL actually exists, you won't be able to connect to it.
About the only thing I could imagine it might be useful for is checking whether a URL "validator" actually works; and it would seem to me that you then have a bit of a "chicken and egg" situation:
You can't validate a URL without knowing what a "valid" one looks like.
You can't write a program to generate valid URLs without knowing what one looks like.
and, unless you're very careful, you could easily end up creating a validator that simply reverse-engineers your generator - including any mistakes it makes.
https://211.34.83.162
http://130.17.174.40/(/%C2%13K/%82xy%6DT#%06%0D%E7%ACu%91gO%FD
https://31.102.186.43:11645
http://5OW.us:12813/D%E5/1%5C%3D%32%EE%3CqVw/%B8%D0*w%F7H#2%80n%CE%4Aw
http://LF6-h.info/T?%3C%6BE%8Fxw%7E%BC#%40k
Third: Even assuming that there are uses for such an animal, a truly random generator is only likely to be good for "smoke tests", and may never (or only very rarely) produce "corner cases" - ie, URLs that are particularly long, problematic, or obscure.
Fourth: Have you tried looking for an existing library to do this? My Google for "valid URL generator" produced a slew of results; although I have to admit that none leap out at me as a "solution" for what you appear to want. I do know that there are any number of solutions (most involving regular expressions) for validating a URL though.
Peter Hoppe wrote:Thank you for your thoughts and taking the time to write!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Peter Hoppe wrote:
I try to write well formatted and documented code and use the Taligent naming conventions. I have always found them very useful.
Peter Hoppe wrote:The validator uses regular expression(s), so I am basically testing those regular expressions.
Jamie Zawinski, in a Tue 12 Aug 1997 Usenet post wrote: Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.
http://p.Z3.net:2918/
https://51.176.251.128:9/&@=/;/%ED/@#
http://9.gov
http://116.250.7.50/_;&%4B;&;&/*:&=//&%DE:///?#
https://le-1.gov
http://110.215.253.4/&=B:=%BE?@
Don't get me started about those stupid light bulbs. |