Skip to content

#1684: Login failed error contains HTML tags #29398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
*/

define([
'uiElement'
], function (Element) {
'uiElement',
'escaper'
], function (Element, escaper) {
'use strict';

return Element.extend({
defaults: {
template: 'Magento_MediaGalleryUi/grid/messages',
messageDelay: 5,
messages: []
messages: [],
allowedTags: ['div', 'span', 'b', 'strong', 'i', 'em', 'u', 'a']
},

/**
Expand Down Expand Up @@ -72,6 +74,16 @@ define([
clearTimeout(timerId);
this.clear();
}.bind(this), Number(delay) * 1000);
},

/**
* Prepare the given message to be rendered as HTML
*
* @param {String} message
* @return {String}
*/
prepareMessageUnsanitizedHtml: function (message) {
return escaper.escapeHtml(message, this.allowedTags);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="messages" outereach="messages">
<div attr="class: 'message message-'+code">
<div data-ui-id="messages-message-error">
<span text="message"></span>
<span data-bind="html: $parent.prepareMessageUnsanitizedHtml(message)"></span>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'Magento_MediaGalleryUi/js/grid/messages'
], function (Messages) {
'use strict';

describe('Magento_MediaGalleryUi/js/grid/messages', function () {
var message,
messageText,
errorType,
successType;

beforeEach(function () {
message = Messages;
messageText = 'test message';
errorType = 'error';
successType = 'success';
});

describe('message handling', function () {
it('add error message, get error message', function () {
message.add(errorType, messageText);
expect(message.get()).toEqual([messageText]);
});

it('add success message, get success message', function () {
message.add(successType, messageText);
expect(message.get()).toEqual([messageText]);
});

it('scheduled cleaning messages', function () {
message.add(errorType, messageText);
message.scheduleCleanup();
expect(message.get()).toEqual([]);
});
});

describe('prepareMessageUnsanitizedHtml', function () {
var messageData,
expectedData;

beforeEach(function () {
messageData = 'Login failed. Please check if the <a href="%1">Secret Key</a> is set correctly and try again.';
expectedData = 'Login failed. Please check if the <a href="%1">Secret Key</a> is set correctly and try again.';
});

it('prepare message to be rendered as HTML', function () {
expect(message.prepareMessageUnsanitizedHtml(messageData)).toEqual(expectedData)
});
});
});
});