Escape @ character in git proxy password

早过忘川 提交于 2019-11-26 07:39:05

I'd try using the URL Encoded value of the @ symbol if you're passing the password in the proxy url:

http.proxy=http://userId:pwd%40123@ipaddress:port

Note (November 2013)

Encoding the url (especially any special character in a password) is the right solution.
The .netrc mentioned below is only for remote repo url, not for the proxy used to resolve said remote repo url.

For said encoding, see "Percent-encoding":

Percent-encoding, also known as URL encoding, is a mechanism for encoding information in a Uniform Resource Identifier (URI) under certain circumstances. Although it is known as URL encoding it is, in fact, used more generally within the main Uniform Resource Identifier (URI) set, which includes both Uniform Resource Locator (URL) and Uniform Resource Name (URN). As such, it is also used in the preparation of data of the application/x-www-form-urlencoded media type, as is often used in the submission of HTML form data in HTTP requests.

Reserved characters after percent-encoding:

!   #   $    &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]
%21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D

Original answer (May 2011)

Two comments:

  • having a password for a server accessed with http (not https) is... strange. The password isn't encrypted during communications between client and server;

  • you could setup a .netrc (or _netrc for Windows) in your $HOME, with the following content

    machine ipaddress:port
    login userId
    password pwd@

The curl used by Git bbehind the scene would handle the encoding just fine, @ or no @.

conal_lab24

URL encode any unusual characters.

List of url codes.

@ character is %40

In my git config file, I have encoded 'just' the user name for instance:

https://myemail%40gmail.com@myrepo.org/api.git

For example, your password stored in environment variable GIT_PASSWORD, username - GIT_USERNAME, then:

git clone http://${GIT_USERNAME}:$(echo -n $GIT_PASSWORD | hexdump -v -e '"x" 1/1 "%02X"' | tr x %)@repository.git

Explanation of: echo -n $GIT_PASSWORD | hexdump -v -e '"x" 1/1 "%02X"' | tr x %

  1. Print password: $GIT_REPOSITORY <- hello
  2. Convert 'hello' to hex: hello <- x68x65x6Cx6Cx6F
  3. Change each 'x' to '%': x68x65x6Cx6Cx6F <- %68%65%6C%6C%6F

You have to percent-encode | encode the special characters. E.g. instead of this:

http://foo:B@r@http-gateway.domain.org:80

you write this:

http://foo:B%40r@http-gateway.domain.org:80

So @ gets replaced with %40.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!