Url parser extensions#2
Conversation
reflect the change.
| ":" split1-last [ url-decode ] | ||
| [ dup [ string>number [ malformed-port ] unless* ] when ] bi* | ||
| [ dup [ dup empty? [ drop f ] [ string>number [ | ||
| malformed-port ] unless* dup 65535 > over 0 < or [ |
There was a problem hiding this comment.
I might clean this up a little by putting on multiple lines, something like:
[
":" split1-last [ url-decode ] [
[ f ] [
string>number [ malformed-port ] unless*
dup 0 65535 between? [ malformed-port ] unless
] if-empty
] bi*
] [ f f ] if*There was a problem hiding this comment.
While the maximum number of ports is 65535 for IPV4 and IPV6 (currently), I'm not sure this limitation should maybe apply to all URLs? Is that what the test suite you are comparing it to does?
There was a problem hiding this comment.
That's a good point, according to this rfc: https://tools.ietf.org/html/rfc1475#section-4.2 later versions of IP allow for ports higher than 65k. We'll remove this checking, as we would still want to support IPvX.
| : unparse-protocol ( url -- ) | ||
| dup protocol>> [ | ||
| % "://" % unparse-host-part | ||
| protocol>> [ |
There was a problem hiding this comment.
Now that the code isn't nested, these probably can each be one-line:
protocol>> [ % ":" % ] when*
dup host>> [ "//" % unparse-host-part ] [ drop ] if|
Cool! Should probably open this PR on the factor/factor repo so we can merge it. |
We extend the url parser to handle missing authorities, and empty usernames, passwords, and ports.
Also sanitychecks the range of the port and extends the prettyprinter to print urls without authorities properly.
Also added some test cases for the aforementioned extensions to the url parser.
We welcome any feedback you might have.