check for encoded components (#18231)

* check for encoded components

* address comments

* relocate and simplify test

* move encodeUrl to notebookLinkHandler

* added comments

* add containsEncodedUri to network.ts
This commit is contained in:
Maddy
2022-02-09 13:36:23 -08:00
committed by GitHub
parent fdf7bbcf60
commit f17e70472f
5 changed files with 62 additions and 3 deletions

View File

@@ -0,0 +1,14 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/**
* Checks if the specified URL is already URI-encoded by checking if there are any unencoded reserved URI component characters
* (such as ?, =, &, /, etc.) in the URL. See https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent for more details.
* @returns true if the URL contains encoded URI component reserved characters
*/
export function containsEncodedUriComponentReservedCharacters(url: string): boolean {
// ie ?,=,&,/ etc
return (decodeURI(url) !== decodeURIComponent(url));
}