Rewrite username validation in todo example to workaround current bug in
parser combinator library.cvs
parent
9efc607ffd
commit
b98e4af5f0
|
@ -191,16 +191,29 @@ USE: parser-combinators
|
||||||
"Register" login-form
|
"Register" login-form
|
||||||
] simple-page ;
|
] simple-page ;
|
||||||
|
|
||||||
: username-parser ( -- parser )
|
: valid-username-char ( ch -- b )
|
||||||
#! Return a parser which parses a valid todo username.
|
#! Return true if the character is valid to appear in a username.
|
||||||
#! That is, it contains only lowercase, uppercase and digits.
|
[
|
||||||
[ letter? ] satisfy
|
[ letter? ] [ drop t ]
|
||||||
[ LETTER? ] satisfy <|>
|
[ LETTER? ] [ drop t ]
|
||||||
[ digit? ] satisfy <|> <!+> just ;
|
[ digit? ] [ drop t ]
|
||||||
|
[ ] [ drop f ]
|
||||||
|
] cond ;
|
||||||
|
|
||||||
: is-valid-username? ( password -- bool )
|
: replace-invalid-username-chars ( str -- str )
|
||||||
|
#! Return a string with invalid username characters mapped to underscores.
|
||||||
|
[
|
||||||
|
dup valid-username-char [
|
||||||
|
] [
|
||||||
|
drop CHAR: _
|
||||||
|
] ifte
|
||||||
|
] str-map ;
|
||||||
|
|
||||||
|
: testx ( string -- b ) dup replace-invalid-username-chars = ;
|
||||||
|
|
||||||
|
: is-valid-username? ( username -- bool )
|
||||||
#! Return true if the username parses correctly
|
#! Return true if the username parses correctly
|
||||||
username-parser call ;
|
dup replace-invalid-username-chars = ;
|
||||||
|
|
||||||
: login-details-valid? ( name password -- )
|
: login-details-valid? ( name password -- )
|
||||||
#! Ensure that a valid username and password were
|
#! Ensure that a valid username and password were
|
||||||
|
|
Loading…
Reference in New Issue