2018-04-13 02:35:55 +02:00
|
|
|
/*
|
2020-03-25 15:28:07 +01:00
|
|
|
Copyright 2018, 2020 New Vector Ltd
|
2018-04-13 02:35:55 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-07-16 14:10:58 +02:00
|
|
|
import { QueryDict, decodeParams } from "matrix-js-sdk/src/utils";
|
2020-04-12 02:54:48 +02:00
|
|
|
|
2016-08-10 01:15:04 +02:00
|
|
|
// We want to support some name / value pairs in the fragment
|
|
|
|
// so we're re-using query string like format
|
|
|
|
//
|
|
|
|
// returns {location, params}
|
2020-03-25 15:07:22 +01:00
|
|
|
export function parseQsFromFragment(location: Location) {
|
2016-08-10 01:15:04 +02:00
|
|
|
// if we have a fragment, it will start with '#', which we need to drop.
|
|
|
|
// (if we don't, this will return '').
|
2018-11-22 19:25:55 +01:00
|
|
|
const fragment = location.hash.substring(1);
|
2016-08-10 01:15:04 +02:00
|
|
|
|
|
|
|
// our fragment may contain a query-param-like section. we need to fish
|
|
|
|
// this out *before* URI-decoding because the params may contain ? and &
|
|
|
|
// characters which are only URI-encoded once.
|
2018-11-22 19:25:55 +01:00
|
|
|
const hashparts = fragment.split('?');
|
2016-08-10 01:15:04 +02:00
|
|
|
|
2018-11-22 19:25:55 +01:00
|
|
|
const result = {
|
2016-08-10 01:15:04 +02:00
|
|
|
location: decodeURIComponent(hashparts[0]),
|
2021-07-16 14:10:58 +02:00
|
|
|
params: <QueryDict>{},
|
2016-08-10 01:15:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (hashparts.length > 1) {
|
2021-07-16 14:10:58 +02:00
|
|
|
result.params = decodeParams(hashparts[1]);
|
2016-08-10 01:15:04 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-07-16 14:10:58 +02:00
|
|
|
export function parseQs(location: Location): QueryDict {
|
|
|
|
return decodeParams(location.search.substring(1));
|
2016-08-10 01:15:04 +02:00
|
|
|
}
|