avoid double-encoding base_url

base_url should already be url-encoded.
Min RK 11 years ago
parent a7721ed341
commit a8b15bc709

@ -21,13 +21,13 @@ define([
LoginWidget.prototype.bind_events = function () {
var that = this;
this.element.find("button#logout").click(function () {
window.location = utils.url_join_encode(
window.location = utils.url_path_join(
that.base_url,
"logout"
);
});
this.element.find("button#login").click(function () {
window.location = utils.url_join_encode(
window.location = utils.url_path_join(
that.base_url,
"login"
);

@ -54,8 +54,8 @@ define([
var parent = utils.url_path_split(editor.file_path)[0];
editor.contents.new_untitled(parent, {type: "file"}).then(
function (data) {
w.location = utils.url_join_encode(
that.base_url, 'edit', data.path
w.location = utils.url_path_join(
that.base_url, 'edit', utils.encode_uri_components(data.path)
);
},
function(error) {
@ -75,8 +75,9 @@ define([
that.save_widget.rename();
});
this.element.find('#download-file').click(function () {
window.open(utils.url_join_encode(
that.base_url, 'files', that.editor.file_path
window.open(utils.url_path_join(
that.base_url, 'files',
utils.encode_uri_components(that.editor.file_path)
) + '?download=1');
});

@ -119,11 +119,11 @@ define([
SaveWidget.prototype.update_address_bar = function (path) {
var state = {path : path};
window.history.replaceState(state, "", utils.url_join_encode(
window.history.replaceState(state, "", utils.url_path_join(
this.editor.base_url,
"edit",
path)
);
utils.encode_uri_components(path)
));
};
SaveWidget.prototype.update_last_modified = function (last_modified) {

@ -36,7 +36,7 @@ define([
KernelSelector.prototype.request_kernelspecs = function() {
// Preliminary documentation for kernelspecs api is at
// https://github.com/ipython/ipython/wiki/IPEP-25%3A-Registry-of-installed-kernels#rest-api
var url = utils.url_join_encode(this.notebook.base_url, 'api/kernelspecs');
var url = utils.url_path_join(this.notebook.base_url, 'api/kernelspecs');
utils.promising_ajax(url).then($.proxy(this._got_kernelspecs, this));
};
@ -292,8 +292,9 @@ define([
var parent = utils.url_path_split(that.notebook.notebook_path)[0];
that.notebook.contents.new_untitled(parent, {type: "notebook"}).then(
function (data) {
var url = utils.url_join_encode(
that.notebook.base_url, 'notebooks', data.path
var url = utils.url_path_join(
that.notebook.base_url, 'notebooks',
utils.encode_uri_components(data.path)
);
url += "?kernel_name=" + kernel_name;
w.location = url;

@ -69,8 +69,8 @@ define([
MenuBar.prototype._nbconvert = function (format, download) {
download = download || false;
var notebook_path = this.notebook.notebook_path;
var url = utils.url_join_encode(
var notebook_path = utils.encode_uri_components(this.notebook.notebook_path);
var url = utils.url_path_join(
this.base_url,
'nbconvert',
format,
@ -92,7 +92,7 @@ define([
* Update header spacer size.
*/
console.warn('`_size_header` is deprecated and will be removed in future versions.'+
' Please trigger the `resize-header.Page` manually if you rely on it.')
' Please trigger the `resize-header.Page` manually if you rely on it.');
this.events.trigger('resize-header.Page');
};
@ -104,7 +104,11 @@ define([
this.element.find('#open_notebook').click(function () {
var parent = utils.url_path_split(that.notebook.notebook_path)[0];
window.open(utils.url_join_encode(that.base_url, 'tree', parent), IPython._target);
window.open(
utils.url_path_join(
that.base_url, 'tree',
utils.encode_uri_components(parent)
), IPython._target);
});
this.element.find('#copy_notebook').click(function () {
if (that.notebook.dirty) {
@ -115,10 +119,11 @@ define([
});
this.element.find('#download_ipynb').click(function () {
var base_url = that.notebook.base_url;
var notebook_path = that.notebook.notebook_path;
var notebook_path = utils.encode_uri_components(that.notebook.notebook_path);
var w = window.open('');
var url = utils.url_join_encode(base_url, 'files', notebook_path)
+ '?download=1';
var url = utils.url_path_join(
base_url, 'files', notebook_path
) + '?download=1';
if (that.notebook.dirty) {
that.notebook.save_notebook().then(function() {
w.location = url;
@ -231,13 +236,13 @@ define([
}
var id_act = id_actions_dict[idx];
if(!that.actions.exists(id_act)){
console.warn('actions', id_act, 'does not exist, still binding it in case it will be defined later...' )
console.warn('actions', id_act, 'does not exist, still binding it in case it will be defined later...');
}
// Immediately-Invoked Function Expression cause JS.
(function(that, id_act, idx){
that.element.find(idx).click(function(event){
that.actions.call(id_act, event)
})
that.actions.call(id_act, event);
});
})(that, id_act, idx);
}

@ -2293,8 +2293,8 @@ define(function (require) {
var parent = utils.url_path_split(this.notebook_path)[0];
this.contents.copy(this.notebook_path, parent).then(
function (data) {
w.location = utils.url_join_encode(
base_url, 'notebooks', data.path
w.location = utils.url_path_join(
base_url, 'notebooks', utils.encode_uri_components(data.path)
);
},
function(error) {

@ -142,10 +142,10 @@ define([
var base_url = this.notebook.base_url;
var path = this.notebook.notebook_path;
var state = {path : path};
window.history.replaceState(state, "", utils.url_join_encode(
window.history.replaceState(state, "", utils.url_path_join(
base_url,
"notebooks",
path)
utils.encode_uri_components(path))
);
};

@ -25,7 +25,8 @@ function($, utils) {
};
ConfigSection.prototype.api_url = function() {
return utils.url_join_encode(this.base_url, 'api/config', this.section_name);
return utils.url_path_join(this.base_url, 'api/config',
utils.encode_uri_components(this.section_name));
};
ConfigSection.prototype._load_done = function() {

@ -43,9 +43,11 @@ define(function(require) {
Contents.prototype.api_url = function() {
var url_parts = [this.base_url, 'api/contents'].concat(
Array.prototype.slice.apply(arguments));
return utils.url_join_encode.apply(null, url_parts);
var url_parts = [
this.base_url, 'api/contents',
utils.url_join_encode.apply(null, arguments),
];
return utils.url_path_join.apply(null, url_parts);
};
/**

@ -274,7 +274,7 @@ define([
}
};
var url = utils.url_join_encode(this.kernel_url, 'interrupt');
var url = utils.url_path_join(this.kernel_url, 'interrupt');
$.ajax(url, {
processData: false,
cache: false,
@ -316,7 +316,7 @@ define([
}
};
var url = utils.url_join_encode(this.kernel_url, 'restart');
var url = utils.url_path_join(this.kernel_url, 'restart');
$.ajax(url, {
processData: false,
cache: false,
@ -362,7 +362,8 @@ define([
that.id = data.id;
that.name = data.name;
}
that.kernel_url = utils.url_join_encode(that.kernel_service_url, that.id);
that.kernel_url = utils.url_path_join(that.kernel_service_url,
encodeURIComponent(that.id));
if (success) {
success(data, status, xhr);
}
@ -394,7 +395,8 @@ define([
* @param {Object} data - information about the kernel including id
*/
this.id = data.id;
this.kernel_url = utils.url_join_encode(this.kernel_service_url, this.id);
this.kernel_url = utils.url_path_join(this.kernel_service_url,
encodeURIComponent(this.id));
this.start_channels();
};
@ -441,7 +443,7 @@ define([
this.ws = new this.WebSocket([
that.ws_url,
utils.url_join_encode(that.kernel_url, 'channels'),
utils.url_path_join(that.kernel_url, 'channels'),
"?session_id=" + that.session_id
].join('')
);
@ -883,20 +885,17 @@ define([
this._msg_queue = this._msg_queue.then(function() {
return serialize.deserialize(e.data);
}).then(function(msg) {return that._finish_ws_message(msg);})
.catch(function(error) {console.error("Couldn't process kernel message", error) });
.catch(function(error) { console.error("Couldn't process kernel message", error); });
};
Kernel.prototype._finish_ws_message = function (msg) {
switch (msg.channel) {
case 'shell':
return this._handle_shell_reply(msg);
break;
case 'iopub':
return this._handle_iopub_message(msg);
break;
case 'stdin':
return this._handle_input_request(msg);
break;
default:
console.error("unrecognized message channel", msg.channel, msg);
}
@ -919,7 +918,7 @@ define([
this._finish_shell(parent_id);
if (shell_callbacks.reply !== undefined) {
promise = promise.then(function() {return shell_callbacks.reply(reply)});
promise = promise.then(function() {return shell_callbacks.reply(reply);});
}
if (content.payload && shell_callbacks.payload) {
promise = promise.then(function() {

@ -32,7 +32,7 @@ define([
NewNotebookWidget.prototype.request_kernelspecs = function () {
/** request and then load kernel specs */
var url = utils.url_join_encode(this.base_url, 'api/kernelspecs');
var url = utils.url_path_join(this.base_url, 'api/kernelspecs');
utils.promising_ajax(url).then($.proxy(this._load_kernelspecs, this));
};
@ -78,8 +78,9 @@ define([
var w = window.open(undefined, IPython._target);
this.contents.new_untitled(that.notebook_path, {type: "notebook"}).then(
function (data) {
var url = utils.url_join_encode(
that.base_url, 'notebooks', data.path
var url = utils.url_path_join(
that.base_url, 'notebooks',
utils.encode_uri_components(data.path)
);
if (kernel_name) {
url += "?kernel_name=" + kernel_name;

@ -75,8 +75,9 @@ define([
$('#new-file').click(function(e) {
var w = window.open('', IPython._target);
that.contents.new_untitled(that.notebook_path || '', {type: 'file', ext: '.txt'}).then(function(data) {
var url = utils.url_join_encode(
that.base_url, 'edit', data.path
var url = utils.url_path_join(
that.base_url, 'edit',
utils.encode_uri_components(data.path)
);
w.location = url;
}).catch(function (e) {
@ -298,7 +299,7 @@ define([
try {
this.add_link(model, item);
} catch(err) {
console.log('Error adding link: ' + err)
console.log('Error adding link: ' + err);
}
}
// Trigger an event when we've finished drawing the notebook list.
@ -550,10 +551,10 @@ define([
item.find(".item_icon").addClass(icon).addClass('icon-fixed-width');
var link = item.find("a.item_link")
.attr('href',
utils.url_join_encode(
utils.url_path_join(
this.base_url,
uri_prefix,
path
utils.encode_uri_components(path)
)
);
@ -613,10 +614,10 @@ define([
var session = this.sessions[path];
if (session) {
var url = utils.url_join_encode(
var url = utils.url_path_join(
this.base_url,
'api/sessions',
session
encodeURIComponent(session)
);
$.ajax(url, settings);
}

@ -62,7 +62,7 @@ define([
success : $.proxy(that.sessions_loaded, this),
error : utils.log_ajax_error,
};
var url = utils.url_join_encode(this.base_url, 'api/sessions');
var url = utils.url_path_join(this.base_url, 'api/sessions');
$.ajax(url, settings);
};

@ -49,14 +49,15 @@ define([
dataType: "json",
success : function (data, status, xhr) {
var name = data.name;
w.location = utils.url_join_encode(base_url, 'terminals', name);
w.location = utils.url_path_join(base_url, 'terminals',
utils.encode_uri_components(name));
},
error : function(jqXHR, status, error){
w.close();
utils.log_ajax_error(jqXHR, status, error);
},
};
var url = utils.url_join_encode(
var url = utils.url_path_join(
this.base_url,
'api/terminals'
);
@ -64,7 +65,7 @@ define([
};
TerminalList.prototype.load_terminals = function() {
var url = utils.url_join_encode(this.base_url, 'api/terminals');
var url = utils.url_path_join(this.base_url, 'api/terminals');
$.ajax(url, {
type: "GET",
cache: false,
@ -92,7 +93,8 @@ define([
item.find(".item_name").text("terminals/" + name);
item.find(".item_icon").addClass("fa fa-terminal");
var link = item.find("a.item_link")
.attr('href', utils.url_join_encode(this.base_url, "terminals", name));
.attr('href', utils.url_path_join(this.base_url, "terminals",
utils.encode_uri_components(name)));
link.attr('target', IPython._target||'_blank');
this.add_shutdown_button(name, item);
};
@ -110,7 +112,8 @@ define([
},
error : utils.log_ajax_error,
};
var url = utils.url_join_encode(that.base_url, 'api/terminals', name);
var url = utils.url_path_join(that.base_url, 'api/terminals',
utils.encode_uri_components(name));
$.ajax(url, settings);
return false;
});

Loading…
Cancel
Save