From f5039ac9af1d8af52bae2246b24372ea10a8f287 Mon Sep 17 00:00:00 2001 From: Steven Hammerton Date: Mon, 12 Oct 2015 10:11:02 +0100 Subject: [PATCH] Use node querystring module to parse query string like name value pairs from fragment --- src/vector/index.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index 8a6a3448..1be71052 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -21,21 +21,20 @@ var sdk = require("matrix-react-sdk"); sdk.loadSkin(require('../skins/vector/skindex')); sdk.loadModule(require('../modules/VectorConferenceHandler')); +var qs = require("querystring"); + var lastLocationHashSet = null; -function parseQueryParams(location) { +// We want to support some name / value pairs in the fragment +// so we're re-using query string ike format +function parseQsFromFragment(location) { var hashparts = location.hash.split('?'); - var params = {}; - if (hashparts.length == 2) { - var pairs = hashparts[1].split('&'); - for (var i = 0; i < pairs.length; ++i) { - var parts = pairs[i].split('='); - if (parts.length != 2) continue; - params[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]); - } + if (hashparts.length > 1) { + console.log(qs.parse(hashparts[1])); + return qs.parse(hashparts[1]); } - return params + return {}; } // Here, we do some crude URL analysis to allow @@ -43,9 +42,9 @@ function parseQueryParams(location) { // deep-links in this example. function routeUrl(location) { if (location.hash.indexOf('#/register') == 0) { - window.matrixChat.showScreen('register', parseQueryParams(location)); + window.matrixChat.showScreen('register', parseQsFromFragment(location)); } else if (location.hash.indexOf('#/login/cas') == 0) { - window.matrixChat.showScreen('cas_login', parseQueryParams(location)); + window.matrixChat.showScreen('cas_login', parseQsFromFragment(location)); } else { window.matrixChat.showScreen(location.hash.substring(2)); }