@@ -74,12 +74,27 @@ var validBrowser = checkBrowserFeatures([
7474
7575// We want to support some name / value pairs in the fragment
7676// so we're re-using query string like format
77+ //
78+ // returns {location, params}
7779function parseQsFromFragment ( location ) {
78- var hashparts = location . hash . split ( '?' ) ;
80+ // if we have a fragment, it will start with '#', which we need to drop.
81+ // (if we don't, this will return '').
82+ var fragment = location . hash . substring ( 1 ) ;
83+
84+ // our fragment may contain a query-param-like section. we need to fish
85+ // this out *before* URI-decoding because the params may contain ? and &
86+ // characters which are only URI-encoded once.
87+ var hashparts = fragment . split ( '?' ) ;
88+
89+ var result = {
90+ location : decodeURIComponent ( hashparts [ 0 ] ) ,
91+ params : { }
92+ } ;
93+
7994 if ( hashparts . length > 1 ) {
80- return qs . parse ( hashparts [ 1 ] ) ;
95+ result . params = qs . parse ( hashparts [ 1 ] ) ;
8196 }
82- return { } ;
97+ return result ;
8398}
8499
85100function parseQs ( location ) {
@@ -92,14 +107,13 @@ function routeUrl(location) {
92107 var params = parseQs ( location ) ;
93108 var loginToken = params . loginToken ;
94109 if ( loginToken ) {
95- window . matrixChat . showScreen ( 'token_login' , parseQs ( location ) ) ;
96- }
97- else if ( location . hash . indexOf ( '#/register' ) == 0 ) {
98- window . matrixChat . showScreen ( 'register' , parseQsFromFragment ( location ) ) ;
99- } else {
100- var hashparts = location . hash . split ( '?' ) ;
101- window . matrixChat . showScreen ( hashparts [ 0 ] . substring ( 2 ) , parseQsFromFragment ( location ) ) ;
110+ window . matrixChat . showScreen ( 'token_login' , params ) ;
111+ return ;
102112 }
113+
114+ var fragparts = parseQsFromFragment ( location ) ;
115+ window . matrixChat . showScreen ( fragparts . location . substring ( 1 ) ,
116+ fragparts . params ) ;
103117}
104118
105119function onHashChange ( ev ) {
@@ -160,13 +174,14 @@ window.onload = function() {
160174function loadApp ( ) {
161175 if ( validBrowser ) {
162176 var MatrixChat = sdk . getComponent ( 'structures.MatrixChat' ) ;
177+ var fragParts = parseQsFromFragment ( window . location ) ;
163178 window . matrixChat = ReactDOM . render (
164179 < MatrixChat
165180 onNewScreen = { onNewScreen }
166181 registrationUrl = { makeRegistrationUrl ( ) }
167182 ConferenceHandler = { VectorConferenceHandler }
168183 config = { configJson }
169- startingQueryParams = { parseQsFromFragment ( window . location ) }
184+ startingQueryParams = { fragParts . params }
170185 enableGuest = { true } /> ,
171186 document . getElementById ( 'matrixchat' )
172187 ) ;
0 commit comments