{"action":"created","issue":{"url":"https://api.github.com/repos/google/go-github/issues/217","labels_url":"https://api.github.com/repos/google/go-github/issues/217/labels{/name}","comments_url":"https://api.github.com/repos/google/go-github/issues/217/comments","events_url":"https://api.github.com/repos/google/go-github/issues/217/events","html_url":"https://github.com/google/go-github/issues/217","id":90513591,"number":217,"title":"go-github incorrectly builds URLs when attempting fetching directory contents","user":{"login":"tarrant","id":39023,"avatar_url":"https://avatars.githubusercontent.com/u/39023?v=3","gravatar_id":"","url":"https://api.github.com/users/tarrant","html_url":"https://github.com/tarrant","followers_url":"https://api.github.com/users/tarrant/followers","following_url":"https://api.github.com/users/tarrant/following{/other_user}","gists_url":"https://api.github.com/users/tarrant/gists{/gist_id}","starred_url":"https://api.github.com/users/tarrant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tarrant/subscriptions","organizations_url":"https://api.github.com/users/tarrant/orgs","repos_url":"https://api.github.com/users/tarrant/repos","events_url":"https://api.github.com/users/tarrant/events{/privacy}","received_events_url":"https://api.github.com/users/tarrant/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-23T23:15:31Z","updated_at":"2015-06-24T17:23:13Z","closed_at":null,"body":"If you call `(s *RepositoriesService) DownloadContents` on a file in the root directory of a repo on github enterprise it will get the dirname, `dir := path.Dir(filepath)`. It then passes this \"dir\" into `(s *RepositoriesService) GetContents`.\r\n\r\nGetContents builds its urls using fmt.Sprintf:\r\n\r\n```\r\nu := fmt.Sprintf(\"repos/%s/%s/contents/%s\", owner, repo, path)\r\n```\r\n\r\nWhen it does this you end up with a url that looks like:\r\n\r\n```\r\n/api/v3/repos/ids/sec_mon/contents//\r\n```\r\n\r\nDue to a bug in github (enterprise?) this will redirect to the User login page.\r\n\r\nIf you use a URL without the double trailing '/' then it works as expected.\r\n\r\nThis can easily be resolved by not building URLs using fmt.Sprintf and instead using path.Join:\r\n\r\n```\r\npath.Join(\"repos\", owner, repo, \"contents\", path)\r\n```\r\n\r\nGithub Enterprise version: Version 2.1.7"},"comment":{"url":"https://api.github.com/repos/google/go-github/issues/comments/114946830","html_url":"https://github.com/google/go-github/issues/217#issuecomment-114946830","issue_url":"https://api.github.com/repos/google/go-github/issues/217","id":114946830,"user":{"login":"willnorris","id":1112,"avatar_url":"https://avatars.githubusercontent.com/u/1112?v=3","gravatar_id":"","url":"https://api.github.com/users/willnorris","html_url":"https://github.com/willnorris","followers_url":"https://api.github.com/users/willnorris/followers","following_url":"https://api.github.com/users/willnorris/following{/other_user}","gists_url":"https://api.github.com/users/willnorris/gists{/gist_id}","starred_url":"https://api.github.com/users/willnorris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willnorris/subscriptions","organizations_url":"https://api.github.com/users/willnorris/orgs","repos_url":"https://api.github.com/users/willnorris/repos","events_url":"https://api.github.com/users/willnorris/events{/privacy}","received_events_url":"https://api.github.com/users/willnorris/received_events","type":"User","site_admin":false},"created_at":"2015-06-24T17:23:13Z","updated_at":"2015-06-24T17:23:13Z","body":"Ah, interesting.  An alternative approach, which would fix this from ever happening anywhere else in the library is to call `path.Clean` inside [NewRequest](https://github.com/google/go-github/blob/fccd5bb66f985db0a0d150342ca0a9529a23488a/github/github.go#L154), since that's all path.Join does to remove duplicate slashes.  I can't think of a scenario where we would ever intentionally want to include any of the things path.Clean removes (double slashes and \".\" or \"..\" path segments)"}}