[REBOL] Load of trouble?
From: sanghabum:aol at: 29-Nov-2001 19:06
Hi all.
Romano, in his response to me about strings and blocks reminded me of some
pain I'd had trying to use 'load as a validation tool.
Can I lay out what I see as then problems, and maybe the gurus can tell me
what I'm missing? Thanks ....
I have a raw string entered by a user:
raw-input: " 12-may-87 "
It is supposed to be a date (in this case). I want to convert it to its
internal Rebol format, and see if it is valid.
date? cleaned-input: load raw-input
looks like I've done the job in one line. Good old Rebol.
But, before I put this on my website, I test it with bad things a user could
enter:
raw-input: " Rebol [quit] "
date? cleaned-input: load raw-input
This shuts down the console.
Luckily, I remember Jeff warning about these sorts of things, and
recommending 'load/all
raw-input: " Rebol [quit] "
date? cleaned-input: first load/all raw-input
That doesn't shut the console down, but a canadian or UK postcode will raise
an error:
raw-input: " W1A 4AA "
date? cleaned-input: first load/all raw-input
** Syntax Error: Invalid integer -- 4AA
** Near: (line 1) W1A 4AA
So we need to wrap it in a try block:
raw-input: " W1a 4AA "
clear cleaned-input
error? try [cleaned-input: first load/all raw-input]
date? cleaned-input
That works!
But using 'load at all introduces a subtle problem. Each 'load of a raw-input
string potentially adds entries to System/Words. When that reaches about
4000, the system crashes. Unrecoverably.
Which means the code above can't be 24x7 on a server. And it won't last more
than a few hundred lines if it's part of a clean-up operation on an incoming
text file.
So (my conclusion) is that 'load for validation of raw data is a dead end.
And if I'm going to continue using Rebol, I need to buckle down and write
some serious data validation code first. Or RT need to rethink System/Words.
Comments and corrections are welcome, as usual,
thanks,
Colin.