Skip to content

Commit d1ac51a

Browse files
authored
Merge pull request #11 from ian-r-rose/escape_urls
Escape URLs
2 parents 7577dbf + da03d73 commit d1ac51a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

jupyterlab_github/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from traitlets import Unicode
88
from traitlets.config import Configurable
99

10-
from notebook.utils import url_path_join
10+
from notebook.utils import url_path_join, url_escape
1111
from notebook.base.handlers import APIHandler
1212

1313
path_regex = r'(?P<path>(?:(?:/[^/]+)+|/?))'
@@ -43,7 +43,7 @@ def get(self, path = ''):
4343
# Get access to the notebook config object
4444
c = GitHubConfig(config=self.config)
4545
try:
46-
api_path = url_path_join(GITHUB_API, path)
46+
api_path = url_path_join(GITHUB_API, url_escape(path))
4747
# If the config has client_id and client_secret set,
4848
# apply them to the request.
4949
if c.client_id != '' and c.client_secret != '':

src/contents.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ class GitHubDrive implements Contents.IDrive {
152152
// appropriate resource.
153153
const repo = path.split('/')[0];
154154
const repoPath = URLExt.join(...path.split('/').slice(1));
155-
const apiPath = URLExt.join('repos', this._user, repo, 'contents', repoPath);
155+
const apiPath = URLExt.encodeParts(
156+
URLExt.join('repos', this._user, repo, 'contents', repoPath));
156157
return this._apiRequest<GitHubContents>(apiPath).then(contents => {
157158
// Set the states
158159
this.validUserState.set(true);
@@ -210,7 +211,8 @@ class GitHubDrive implements Contents.IDrive {
210211
const repo = path.split('/')[0];
211212
const repoPath = URLExt.join(...path.split('/').slice(1));
212213
const dirname = PathExt.dirname(repoPath);
213-
const dirApiPath = URLExt.join('repos', this._user, repo, 'contents', dirname);
214+
const dirApiPath = URLExt.encodeParts(
215+
URLExt.join('repos', this._user, repo, 'contents', dirname));
214216
return this._apiRequest<GitHubDirectoryListing>(dirApiPath).then(dirContents => {
215217
for (let item of dirContents) {
216218
if (item.path === repoPath) {
@@ -346,7 +348,8 @@ class GitHubDrive implements Contents.IDrive {
346348
const repo = path.split('/')[0];
347349
const repoPath = URLExt.join(...path.split('/').slice(1));
348350
const dirname = PathExt.dirname(repoPath);
349-
const dirApiPath = URLExt.join('repos', this._user, repo, 'contents', dirname);
351+
const dirApiPath = URLExt.encodeParts(
352+
URLExt.join('repos', this._user, repo, 'contents', dirname));
350353
return this._apiRequest<GitHubDirectoryListing>(dirApiPath).then(dirContents => {
351354
for (let item of dirContents) {
352355
if (item.path === repoPath) {
@@ -357,8 +360,8 @@ class GitHubDrive implements Contents.IDrive {
357360
throw Error('Cannot find sha for blob');
358361
}).then(sha => {
359362
//Once we have the sha, form the api url and make the request.
360-
const blobApiPath = URLExt.join(
361-
'repos', this._user, repo, 'git', 'blobs', sha);
363+
const blobApiPath = URLExt.encodeParts(URLExt.join(
364+
'repos', this._user, repo, 'git', 'blobs', sha));
362365
return this._apiRequest<GitHubBlob>(blobApiPath);
363366
}).then(blob => {
364367
//Convert the data to a Contents.IModel.
@@ -374,7 +377,8 @@ class GitHubDrive implements Contents.IDrive {
374377
private _listRepos(): Promise<Contents.IModel> {
375378
return new Promise<Contents.IModel>((resolve, reject) => {
376379
// Try to find it under orgs.
377-
const apiPath = URLExt.join('users', this._user, 'repos');
380+
const apiPath = URLExt.encodeParts(
381+
URLExt.join('users', this._user, 'repos'));
378382
this._apiRequest<GitHubRepo[]>(apiPath).then(repos => {
379383
this.validUserState.set(true);
380384
this.rateLimitedState.set(false);

0 commit comments

Comments
 (0)