Bug 549690 - JGit Invalidates a legal URL causing "cannot open git-upload-pack" error on push
Summary: JGit Invalidates a legal URL causing "cannot open git-upload-pack" error on push
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.4   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: 5.6   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-31 11:14 EDT by Chris Jones CLA
Modified: 2019-10-30 19:24 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Jones CLA 2019-07-31 11:14:33 EDT
I have a "." in my Windows domain ID, which causes JGit to fail when I attempt to PUSH to a Git server. This works OK from Git Bash. 

The stack trace reports an invalid character at position 7.

I've tried escaping the "." with %5E but the same error occurs.

The error appears to be in org.eclipse.jgit.util.HttpSupport.proxyFor(..)

Stack trace
===========

!MESSAGE An exception occurred during push on URI http://infor\c.jones@somehost/Bonobo.Git.Server/someproject.git: http://infor\c.jones@somehost/Bonobo.Git.Server/someproject.git: cannot open git-receive-pack
!STACK 0
org.eclipse.jgit.errors.TransportException: http://infor\c.jones@somehost/Bonobo.Git.Server/someproject.git: cannot open git-receive-pack
	at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:587)
	at org.eclipse.jgit.transport.TransportHttp.openPush(TransportHttp.java:438)
	at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:160)
	at org.eclipse.jgit.transport.Transport.push(Transport.java:1346)
	at org.eclipse.egit.core.op.PushOperation.run(PushOperation.java:191)
	at org.eclipse.egit.ui.internal.push.ConfirmationPage$2.run(ConfirmationPage.java:211)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Caused by: java.net.ConnectException: Cannot determine proxy for http://infor\c.jones@somehost/Bonobo.Git.Server/someproject.git/info/refs?service=git-receive-pack
	at org.eclipse.jgit.util.HttpSupport.proxyFor(HttpSupport.java:284)
	at org.eclipse.jgit.transport.TransportHttp.httpOpen(TransportHttp.java:817)
	at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:494)
	... 6 more
Caused by: java.net.URISyntaxException: Illegal character in authority at index 7: http://infor\c.jones@somehost/Bonobo.Git.Server/someproject.git/info/refs?service=git-receive-pack
	at java.net.URI$Parser.fail(URI.java:2848)
	at java.net.URI$Parser.parseAuthority(URI.java:3186)
	at java.net.URI$Parser.parseHierarchical(URI.java:3097)
	at java.net.URI$Parser.parse(URI.java:3053)
	at java.net.URI.<init>(URI.java:588)
	at java.net.URL.toURI(URL.java:946)
	at org.eclipse.jgit.util.HttpSupport.proxyFor(HttpSupport.java:281)
Comment 1 Thomas Wolf CLA 2019-07-31 12:35:15 EDT
The problem is not the colon (and %5E would be a caret ^), but the backslash (which is %5C).

The error reporting is a bit strange, character 7 is counted from the beginning, so is the "i" after "http://".

But maybe a solution for JGit might be to not convert the whole URL to a URI but only use scheme, hostname, and port to find the proxy.
Comment 2 Eclipse Genie CLA 2019-07-31 13:42:37 EDT
New Gerrit change created: https://git.eclipse.org/r/146884
Comment 3 Thomas Wolf CLA 2019-08-01 04:27:14 EDT
BTW: userinfo in HTTP URLs is a questionable idea anyway. RFC 2616 did not even include it for URLs, RFC 7230 does for http URIs, but cautions against its use. RFC 3986 (defining URIs) clearly does not allow backslashes in the userinfo component; they must be %-encoded: https://tools.ietf.org/html/rfc3986#section-3.2.1 .
Comment 4 Chris Jones CLA 2019-08-19 04:48:28 EDT
I still think the problem is most likely the "." in "c.jones" as I originally said. If we ignore the http://, then position 7 is the last character in this part "infor/c."

It wouldn't be the first time that had caused an issue for me.

Apologies for the typo previously - I meant %2E not %5E
Comment 5 Thomas Wolf CLA 2019-08-19 04:56:54 EDT
(In reply to Chris Jones from comment #4)
> I still think the problem is most likely the "." in "c.jones" as I
> originally said. If we ignore the http://, then position 7 is the last
> character in this part "infor/c."
> 
> It wouldn't be the first time that had caused an issue for me.
> 
> Apologies for the typo previously - I meant %2E not %5E

Run this through the debugger and see for yourself if you don't believe me:

URI broken = new URI("http://infor\\c.jones@somehost/Bonobo.Git.Server/someproject.git");

And the try the following:

URI uri = new URI("http://infor%5Cc.jones@somehost/Bonobo.Git.Server/someproject.git");

The problem is the backslash, which is not allowed in the userinfo in a URI.
Comment 6 Eclipse Genie CLA 2019-10-30 19:20:45 EDT
Gerrit change https://git.eclipse.org/r/146884 was merged to [master].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=b7d1eb4185aa35f037790580b60c1f2d76968fa8