mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-23 18:04:28 -06:00
Fix issue #373 problems in urls with special characters
Added function to escape URLs entered via JS prompt. It's a partial fix because people cannot be stopped entering URLs manually and forgetting to escape them.
This commit is contained in:
parent
4fb35f2758
commit
5d0294f5f5
@ -848,6 +848,8 @@ function drawLink(editor) {
|
|||||||
if (!url) {
|
if (!url) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (/[()<>]/.test(url)) url = escapeUrl(url);
|
||||||
}
|
}
|
||||||
_replaceSelection(cm, stat.link, options.insertTexts.link, url);
|
_replaceSelection(cm, stat.link, options.insertTexts.link, url);
|
||||||
}
|
}
|
||||||
@ -865,10 +867,26 @@ function drawImage(editor) {
|
|||||||
if (!url) {
|
if (!url) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (/[()<>]/.test(url)) url = escapeUrl(url);
|
||||||
}
|
}
|
||||||
_replaceSelection(cm, stat.image, options.insertTexts.image, url);
|
_replaceSelection(cm, stat.image, options.insertTexts.image, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape URLs to prevent breaking up rendered Markdown links
|
||||||
|
* @param url {string} The url of the link or image
|
||||||
|
*/
|
||||||
|
function escapeUrl(url) {
|
||||||
|
|
||||||
|
url = url.replace(/\(/g,'\\(')
|
||||||
|
.replace(/\)/g,'\\)')
|
||||||
|
.replace(/</g,'\\<')
|
||||||
|
.replace(/>/g,'\\>');
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for opening the browse-file window to upload an image to a server.
|
* Action for opening the browse-file window to upload an image to a server.
|
||||||
* @param editor {EasyMDE} The EasyMDE object
|
* @param editor {EasyMDE} The EasyMDE object
|
||||||
|
Loading…
x
Reference in New Issue
Block a user