From 3a09484621b95d29989990845c4d18352dfc9504 Mon Sep 17 00:00:00 2001 From: Sheng Date: Sat, 18 May 2019 16:36:21 +0800 Subject: [PATCH] Added function decode_uri --- webssh/static/js/main.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/webssh/static/js/main.js b/webssh/static/js/main.js index d7d321a..14ed097 100644 --- a/webssh/static/js/main.js +++ b/webssh/static/js/main.js @@ -85,6 +85,16 @@ jQuery(function($){ restore_items(fields); + function decode_uri(uri) { + try { + return decodeURI(uri); + } catch(e) { + console.error(e); + } + return ''; + } + + function parse_url_data(string, filter_keys) { var i, pair, key, val, map = {}, @@ -92,8 +102,8 @@ jQuery(function($){ for (i = 0; i < arr.length; i++) { pair = arr[i].split('='); - key = pair[0].toLowerCase(); - val = pair[1]; + key = pair[0].trim().toLowerCase(); + val = pair[1] && pair[1].trim(); if (filter_keys.indexOf(key) !== -1) { map[key] = val; @@ -660,7 +670,7 @@ jQuery(function($){ url_data = parse_url_data( - window.location.search.substring(1) + '&' + window.location.hash.substring(1), + decode_uri(window.location.search.substring(1)) + '&' + decode_uri(window.location.hash.substring(1)), fields.concat(['password', 'bgcolor', 'title']) ); console.log(url_data);