Skip to content

WYSIWYG editor fails to parse directives of files with special characters in URL (so random files) #18138

@adammada

Description

@adammada

Preconditions

  1. 2.2.5

Steps to reproduce

  1. Open WYSIWYG editor for a product select option to insert image and upload file which base64 encoded filename would use any of special allowed characters (like =), for example: regular_png_.png

  2. Select uploaded image and insert it. In upload dialog in Image URL field you will see URL like:

http://magento2.local/admin/cms/wysiwyg/directive/___directive/e3ttZWRpYSB1cmw9Ind5c2l3eWcvcmVndWxhcl9wbmdfLnBuZyJ9fQ%2C%2C/key/3f5dc8b87aa830fa268477f1c1f8ac2e4ac2e435234c4b8d6affec1201033b3a/

Notice: "%2C%2C" part of URL.

  1. Image will be correctly displayed in WYSIWYG editor.

  2. Click "Show/Hide editor" to check result

Expected result

<img src="{{media url="wysiwyg/regular_png_.png"}}" />

Actual result

<img src="http://magento2.local/admin/cms/wysiwyg/directive/___directive/e3ttZWRpYSB1cmw9Ind5c2l3eWcvcmVndWxhcl9wbmdfLnBuZyJ9fQ%2C%2C/key/3f5dc8b87aa830fa268477f1c1f8ac2e4ac2e435234c4b8d6affec1201033b3a/" width="472" height="472" />

I was trying to track that bug down by myself. It all comes to the fact that directive url generated by "onInsert" action uses standard urlencoder, which uses standard PHP "rawurlencode" function.

That function turns base64 encoded (= is turned into "," after encoding)
"e3ttZWRpYSB1cmw9Ind5c2l3eWcvcmVndWxhcl9wbmdfLnBuZyJ9fQ,,"
into
"e3ttZWRpYSB1cmw9Ind5c2l3eWcvcmVndWxhcl9wbmdfLnBuZyJ9fQ%2C%2C"

WYSIWYG editor on the other hand expects decoded URL like: "e3ttZWRpYSB1cmw9Ind5c2l3eWcvcmVndWxhcl9wbmdfLnBuZyJ9fQ,,"

https://github.com/magento/magento2/blob/2.2/lib/web/mage/adminhtml/wysiwyg/tiny_mce/setup.js#L461

var url = this.makeDirectiveUrl('%directive%').replace(/([$^.?*!+:=()\[\]{}|\\])/g, '\\$1'),
reg = new RegExp(url.replace('%directive%', '([a-zA-Z0-9,_-]+)'));

So the rexexp part does not find URLS containing "%" at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: Format is validGate 1 Passed. Automatic verification of issue format passed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions