[jcifs] Question about userinfo encoding?

Sean Daley spdaley at gmail.com
Mon Jul 11 12:16:32 MDT 2011

According to the SmbFile javadoc, the userinfo component of the SMB
URL must be URL encoded but
then it goes on to say that JCIFS will work correctly with anything
but '@' and '%' encoded.  I first
interpreted that to mean that when using JCIFS, I should only really
need to worry about encoding '@'
and '%'.  Unfortunately we then had a password with a '#' in it and
the URL blew up.  When using
JCIFS, should we make sure that we always URL encode the userinfo
component?  Or am I doing
something else wrong here?  An example program with using a '#' is as follows:

import java.net.MalformedURLException;

import jcifs.smb.SmbFile;

public class TestJcifs
    public static void main(String[] args) throws MalformedURLException
        String url = "smb://Administrator:pass#word@testserver/ADMIN$/";
        SmbFile file = new SmbFile(url);
        System.out.println(url + " converts to '" + file.getURL() + "'");

        url = "smb://Administrator:pass%23word@testserver/ADMIN$/";
        file = new SmbFile(url);
        System.out.println(url + " converts to '" + file.getURL() + "'");

Running this program yields:
smb://Administrator:pass#word@testserver/ADMIN$/ converts to
smb://Administrator:pass%23word@testserver/ADMIN$/ converts to

The URL with the unencoded '#' in it gets messed up.  If it helps,
this was tested using Java 1.6.



More information about the jCIFS mailing list