Skip to content

Commit c81c1cb

Browse files
committed
Refactor to use url_path_join to avoid trailing slash ambiguity
1 parent bdd3360 commit c81c1cb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

nbviewer/providers/github/handlers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
base64_decode,
3030
quote,
3131
response_text,
32+
url_path_join,
3233
)
3334

3435
from .client import AsyncGitHubClient
@@ -291,12 +292,13 @@ class GitHubBlobHandler(GithubClientMixin, RenderingHandler):
291292
@gen.coroutine
292293
def get_notebook_data(self, user, repo, ref, path):
293294
if os.environ.get('GITHUB_API_URL', '') == '':
294-
raw_pattern = u"https://raw.githubusercontent.com/{user}/{repo}/{ref}/{path}"
295+
raw_url = u"https://raw.githubusercontent.com/{user}/{repo}/{ref}/{path}".format(
296+
user=user, repo=repo, ref=ref, path=quote(path)
297+
)
295298
else: #Github Enterprise has a different URL pattern for accessing raw files
296-
raw_pattern = u"{github_url}{user}/{repo}/raw/{ref}/{path}"
297-
raw_url = raw_pattern.format(
298-
user=user, repo=repo, ref=ref, path=quote(path), github_url=self.github_url
299-
)
299+
raw_url = url_path_join(
300+
self.github_url, user, repo, 'raw', ref, quote(path)
301+
)
300302
blob_url = u"{github_url}{user}/{repo}/blob/{ref}/{path}".format(
301303
user=user, repo=repo, ref=ref, path=quote(path), github_url=self.github_url
302304
)

0 commit comments

Comments
 (0)