From 59347d8057ed8db93045d99bb848742301902910 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Mon, 22 Jan 2024 14:49:55 +0100 Subject: [PATCH] TinyMCE: Trim spaces from pasted links It's a common occurrence for pasted content to contain a space at the end. For links, this can make the links invalid, as TinyMCE will URL-encode that space and make it meaningful - even though it is not. This commit trims whitespace from URLs before setting them in TinyMCE. --- app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee b/app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee index a90a55179c..0e98029d37 100644 --- a/app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee +++ b/app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee @@ -129,10 +129,11 @@ class window.Alchemy.LinkDialog extends Alchemy.Dialog # Sets the link either in TinyMCE or on an Ingredient. setLink: (url, title, target) -> + trimmedUrl = url.trim() if @link_object.editor - @setTinyMCELink(url, title, target) + @setTinyMCELink(trimmedUrl, title, target) else - @link_object.setLink(url, title, target, @link_type) + @link_object.setLink(trimmedUrl, title, target, @link_type) return # Sets a link in TinyMCE editor.