Skip to content

Escape URLs #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jupyterlab_github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from traitlets import Unicode
from traitlets.config import Configurable

from notebook.utils import url_path_join
from notebook.utils import url_path_join, url_escape
from notebook.base.handlers import APIHandler

path_regex = r'(?P<path>(?:(?:/[^/]+)+|/?))'
Expand Down Expand Up @@ -43,7 +43,7 @@ def get(self, path = ''):
# Get access to the notebook config object
c = GitHubConfig(config=self.config)
try:
api_path = url_path_join(GITHUB_API, path)
api_path = url_path_join(GITHUB_API, url_escape(path))
# If the config has client_id and client_secret set,
# apply them to the request.
if c.client_id != '' and c.client_secret != '':
Expand Down
16 changes: 10 additions & 6 deletions src/contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ class GitHubDrive implements Contents.IDrive {
// appropriate resource.
const repo = path.split('/')[0];
const repoPath = URLExt.join(...path.split('/').slice(1));
const apiPath = URLExt.join('repos', this._user, repo, 'contents', repoPath);
const apiPath = URLExt.encodeParts(
URLExt.join('repos', this._user, repo, 'contents', repoPath));
return this._apiRequest<GitHubContents>(apiPath).then(contents => {
// Set the states
this.validUserState.set(true);
Expand Down Expand Up @@ -210,7 +211,8 @@ class GitHubDrive implements Contents.IDrive {
const repo = path.split('/')[0];
const repoPath = URLExt.join(...path.split('/').slice(1));
const dirname = PathExt.dirname(repoPath);
const dirApiPath = URLExt.join('repos', this._user, repo, 'contents', dirname);
const dirApiPath = URLExt.encodeParts(
URLExt.join('repos', this._user, repo, 'contents', dirname));
return this._apiRequest<GitHubDirectoryListing>(dirApiPath).then(dirContents => {
for (let item of dirContents) {
if (item.path === repoPath) {
Expand Down Expand Up @@ -346,7 +348,8 @@ class GitHubDrive implements Contents.IDrive {
const repo = path.split('/')[0];
const repoPath = URLExt.join(...path.split('/').slice(1));
const dirname = PathExt.dirname(repoPath);
const dirApiPath = URLExt.join('repos', this._user, repo, 'contents', dirname);
const dirApiPath = URLExt.encodeParts(
URLExt.join('repos', this._user, repo, 'contents', dirname));
return this._apiRequest<GitHubDirectoryListing>(dirApiPath).then(dirContents => {
for (let item of dirContents) {
if (item.path === repoPath) {
Expand All @@ -357,8 +360,8 @@ class GitHubDrive implements Contents.IDrive {
throw Error('Cannot find sha for blob');
}).then(sha => {
//Once we have the sha, form the api url and make the request.
const blobApiPath = URLExt.join(
'repos', this._user, repo, 'git', 'blobs', sha);
const blobApiPath = URLExt.encodeParts(URLExt.join(
'repos', this._user, repo, 'git', 'blobs', sha));
return this._apiRequest<GitHubBlob>(blobApiPath);
}).then(blob => {
//Convert the data to a Contents.IModel.
Expand All @@ -374,7 +377,8 @@ class GitHubDrive implements Contents.IDrive {
private _listRepos(): Promise<Contents.IModel> {
return new Promise<Contents.IModel>((resolve, reject) => {
// Try to find it under orgs.
const apiPath = URLExt.join('users', this._user, 'repos');
const apiPath = URLExt.encodeParts(
URLExt.join('users', this._user, 'repos'));
this._apiRequest<GitHubRepo[]>(apiPath).then(repos => {
this.validUserState.set(true);
this.rateLimitedState.set(false);
Expand Down