Topic on Extension talk:TinyMCE

Jump to navigation Jump to search

Bug wrt external links containing underscores ("_")

5
Summary by DuncanCrane

Change suggesed by Hermann has been added to the master branch

HermannSchwärzler (talkcontribs)

When one creates/edits an external link that contains an '_' in its link URL the URL gets split at the '_' and the part after the first '_' becomes part of the link text.

This is due to the fact that in tinymce/plugins/mw_wikicode/plugin.js the insertLink function replaces every '_' in the URL with a space (' ') even for external links. And that's a bug as this should only be done for internal links (if at all).

My solution for this are these changes to that file:

--- a/tinymce/plugins/mw_wikicode/plugin.js 
+++ b/tinymce/plugins/mw_wikicode/plugin.js 
@@ -2894,11 +2894,12 @@ var MwWikiCode = function() {
                                        //This is necessary to avoid the bswikicode parser from breaking the markup
                                        var href = data.href.replace(/(^.*?\[|\].*?$|\r\n|\r|\n)/gm, ''); //first layer of '[...]' //external-, file- and mailto- links''
                                        href = href.replace(/(^.*?\[|\].*?$|\r\n|\r|\n)/gm, ''); //potential second layer of '[[...]]' //internal and interwiki links''
-                                       var aLink = decodeURIComponent(href).replace("_"," "); 
+                                       var aLink = decodeURIComponent(href);
                                        var aLabel = decodeURI(data.text).replace("_"," ");
                                        var wikitext = "";
                                        
                                        if (data["class"] == "link internal mw-internal-link mceNonEditable") { 
+                                               aLink = aLink.replace("_"," ");
                                                if (aLabel) {
                                                        wikitext = "[[" + aLink + "|" + aLabel + "]]";
                                                } else {

Is this a valid solution or am I missing something?

DuncanCrane (talkcontribs)

Hi Hermann

Firstly my apologies for such a long delay. I seem to have a problem that I'm not getting notified of posts to this page which is probably down to my incompetence! Secondly, thank you for trying this extension and taking the trouble to both let me know of this problem AND provide a solution.

What you observed was a bug and what you gave was a valid solution. I'll add it to the master branch over the next day or so and I do hope you will continue to use the TinyMCE extension and let me now of any problems or suggestions.

Kind regards

DuncanCrane (talk) 18:05, 19 June 2019 (UTC)

89.246.165.171 (talkcontribs)

We are still facing the same problem with the currently available version.

DuncanCrane (talkcontribs)

Hi Hermann I am sorry, I somehow overlooked adding the change back to the master. I'll look into it over the next few days. Your patch should still work in the meantime. Many thanks - Duncan

86.164.120.53 (talkcontribs)

Hi Hermann - it should now be available in the master code.