Fwd: xmerl ftp URI parsing patch

Steve Vinoski vinoski@REDACTED
Wed Aug 26 20:59:06 CEST 2009


I haven't seen any replies to the patch below, and given that I sent it
during the height of summer holidays and also given recent problems I've had
sending to these mailing lists, I thought I'd resend just in case.
--steve

---------- Forwarded message ----------
From: Steve Vinoski <vinoski@REDACTED>
Date: Thu, Jul 16, 2009 at 12:54 AM
Subject: xmerl ftp URI parsing patch
To: erlang-bugs@REDACTED


The xmerl_uri:parse function can't handle FTP URIs containing username
and password. Also, the default FTP port constant in xmerl_uri.erl is
wrong. Here's a patch against R13B01 that I believe remedies these
issues. I tried to write it to match the style of the other code in
that file.

I manually ran a few of the W3C XML schema URI test FTP URIs against
this and they all looked good. Note, though, that this patch doesn't
handle encoded :, @, or / characters appearing within the username or
password fields as required by RFC 1738. Note also that I left the
"FIXME" comment in the code, but with these changes you might want to
consider removing it.

These changes also work for R12B-5 but the line offsets are different.

--steve

--- otp_src_R13B01/lib/xmerl/src/xmerl_uri.erl  2009-03-12
08:27:06.000000000 -0400
+++ xmerl_uri.erl       2009-07-16 00:44:27.000000000 -0400
@@ -120,7 +120,7 @@

 %%%
............................................................................
 %%% FIXME!!! This is just a quick hack that doesn't work!
--define(FTP_DEFAULT_PORT, 80).
+-define(FTP_DEFAULT_PORT, 21).

 %%% FTP (Source RFC 2396, RFC 1738, RFC 959)
 %%% Note: This BNF has been modified to better fit with RFC 2396
@@ -155,9 +155,21 @@
    end.

 ftp_userinfo(C0) ->
-    User="",
-    Password="",
-    {C0,{User,Password}}.
+    ftp_userinfo(C0,0,[],[],[]).
+ftp_userinfo([],_,Acc,User,Passwd) ->
+    {lists:reverse(Acc),{User,Passwd}};
+ftp_userinfo(C0=[$/|_],_,Acc,User,Passwd) ->
+    {lists:reverse(Acc)++C0,{User,Passwd}};
+ftp_userinfo([$@|C0],1,Acc,User,[]) ->
+    {C0,{User,lists:reverse(Acc)}};
+ftp_userinfo([$@|C0],0,Acc,[],[]) ->
+    {C0,{lists:reverse(Acc),""}};
+ftp_userinfo([$:|_],0,[],[],[]) ->
+    {error,no_user};
+ftp_userinfo([$:|C0],0,Acc,[],[]) ->
+    ftp_userinfo(C0,1,[],lists:reverse(Acc),[]);
+ftp_userinfo([C|C0],Stage,Acc,User,Passwd) ->
+    ftp_userinfo(C0,Stage,[C|Acc],User,Passwd).


 %%%
.........................................................................


More information about the erlang-patches mailing list