[Console] Fix bug in which loading from a remote url fails when View in Console button is clicked in Elastic docs #144003

Co-authored-by: Muhammad Ibragimov <muhammad.ibragimov@elastic.co>
This commit is contained in:
Muhammad Ibragimov 2022-10-26 16:47:53 +05:00 committed by GitHub
parent 2e03c3a60b
commit b7c8011f33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -115,7 +115,9 @@ function EditorUI({ initialTextValue, setEditorInstance }: EditorProps) {
const loadBufferFromRemote = (url: string) => {
const coreEditor = editor.getCoreEditor();
if (/^https?:\/\//.test(url)) {
// Normalize and encode the URL to avoid issues with spaces and other special characters.
const encodedUrl = new URL(url).toString();
if (/^https?:\/\//.test(encodedUrl)) {
const loadFrom: Record<string, any> = {
url,
// Having dataType here is required as it doesn't allow jQuery to `eval` content