forked from jitsi/jitsi-meet-electron
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bring back upstream changes that got lost with the revert of the 2022…
….9.1 merge
- Loading branch information
Showing
7 changed files
with
113 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import Bourne from '@hapi/bourne'; | ||
|
||
/** | ||
* Prints the error and reports it to the global error handler. | ||
* | ||
* @param {Error} e - The error object. | ||
* @param {string} msg - A custom message to print in addition to the error. | ||
* @returns {void} | ||
*/ | ||
export function reportError(e, msg = '') { | ||
console.error(msg, e); | ||
window.onerror && window.onerror(msg, undefined, undefined, undefined, e); | ||
} | ||
|
||
|
||
/** | ||
* A list if keys to ignore when parsing. | ||
* | ||
* @type {string[]} | ||
*/ | ||
const blacklist = [ '__proto__', 'constructor', 'prototype' ]; | ||
|
||
/** | ||
* Parses the query/search or fragment/hash parameters out of a specific URL and | ||
* returns them as a JS object. | ||
* | ||
* @param {URL} url - The URL to parse. | ||
* @param {boolean} dontParse - If falsy, some transformations (for parsing the | ||
* value as JSON) will be executed. | ||
* @param {string} source - If {@code 'search'}, the parameters will parsed out | ||
* of {@code url.search}; otherwise, out of {@code url.hash}. | ||
* @returns {Object} | ||
*/ | ||
export function parseURLParams( | ||
url, | ||
dontParse = false, | ||
source = 'hash') { | ||
if (typeof url === 'string') { | ||
// eslint-disable-next-line no-param-reassign | ||
url = new URL(url); | ||
} | ||
const paramStr = source === 'search' ? url.search : url.hash; | ||
const params = {}; | ||
const paramParts = (paramStr && paramStr.substring(1).split('&')) || []; | ||
|
||
// Detect and ignore hash params for hash routers. | ||
if (source === 'hash' && paramParts.length === 1) { | ||
const firstParam = paramParts[0]; | ||
|
||
if (firstParam.startsWith('/') && firstParam.split('&').length === 1) { | ||
return params; | ||
} | ||
} | ||
|
||
paramParts.forEach(part => { | ||
const param = part.split('='); | ||
const key = param[0]; | ||
|
||
if (!key || key.split('.').some(k => blacklist.includes(k))) { | ||
return; | ||
} | ||
|
||
let value; | ||
|
||
try { | ||
value = param[1]; | ||
|
||
if (!dontParse) { | ||
const decoded = decodeURIComponent(value).replace(/\\&/, '&'); | ||
|
||
value = decoded === 'undefined' ? undefined : Bourne.parse(decoded); | ||
} | ||
} catch (e) { | ||
reportError( | ||
e, `Failed to parse URL parameter value: ${String(value)}`); | ||
|
||
return; | ||
} | ||
params[key] = value; | ||
}); | ||
|
||
return params; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters