User tests: Successful: Unsuccessful:
Pull Request for New Issue.
Fix improper js escaping in toolbar buttons.
test "test" 'test'"
for admin en-GB JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST
language varNone.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Title |
|
Title |
|
Labels |
Added:
?
|
Category | Libraries | ⇒ | Libraries Unit Tests |
Labels |
Added:
?
|
@andrepereiradasilva Can't you move that inline JavaScript into a script tag / file at all? ;) *duck
@andrepereiradasilva here is my approach (batch button):
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_BASE') or die;
JHtml::_('behavior.core');
$title = $displayData['title'];
$message = JText::script('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');
JFactory::getDocument()->addScriptDeclaration(
<<<JS
document.addEventListener("DOMContentLoaded", function() {
var toolbarButtons = document.querySelectorAll("button.js-toolbar");
for (var i = 0, j = toolbarButtons.length; i < j; i++) {
toolbarButtons[i].addEventListener('click', function(e) {
if (e.target.getAttribute('data-button') === "batch") {
if (document.adminForm.boxchecked.value === 0) {
alert(Joomla.JText._("JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST"));
} else{
jQuery('#collapseModal' ).modal('show');
return true;
}
}
})
}
});
JS
)
?>
<button class="btn btn-small js-toolbar" data-button="batch" data-toggle="modal">
<span class="icon-checkbox-partial" title="<?php echo $title; ?>"></span>
<?php echo $title; ?>
</button>
Don't mind the inline script, this would be one static toolbar.js file that will cover all the buttons
@andrepereiradasilva @yvesh do you approve the approach?
We have other similar issues in other places than toolbar, where adding a simple true
solves the double quotes.
Example: https://github.com/joomla/joomla-cms/blob/staging/plugins/installer/packageinstaller/tmpl/default.php#L22
alert("' . JText::_('PLG_INSTALLER_PACKAGEINSTALLER_NO_PACKAGE', true) . '");
@andrepereiradasilva @yvesh do you approve the approach?
as long toolbar B/C is preserved for me is ok.
Also if you use DOMContentLoaded you need to add the event polyfill for ie8. BTW what do you think of convert the alert
in a joomla error message?
We have other similar issues in other places than toolbar, where adding a simple true solves the double quotes.
yes, a quick fix would be set that to "true", because JText::_()
has that option exactly for when dump text string from php directly to inline JS code
See https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/language/text.php#L44
JText::script()
AFAIK already escapes the js strings because in 3.7.0 it uses the JDocument::addScriptOptions
method which is rendered with json_encode
and IMHO is the most correct way to send text vars to js, in that case no need to escape them.
See https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/language/text.php#L404
And https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/document/renderer/html/head.php#L239
Also if you use DOMContentLoaded you need to add the event polyfill for ie8. BTW what do you think of convert the alert in a joomla error message?
+1! We should get rid of all alerts if possible.
@dgt41 good work! Only a bit code style (missing space after else etc).
http://php.net/manual/de/language.types.string.php#language.types.string.syntax.nowdoc
I have tested this item
Test 2 times (on "Articles" and "Menu").
@andrepereiradasilva Batch should be added in this PR.
I will make now a PR for other instances of alert
I have tested this item
Test OK
Status | Pending | ⇒ | Ready to Commit |
Labels |
RTC
This should not be RTCed. It misses the code for toolbar batch button.
Please @andrepereiradasilva complete this patch.
I made PR towards yours, @andrepereiradasilva
andrepereiradasilva#122
Category | Libraries Unit Tests | ⇒ | Layout Libraries Unit Tests |
patch added
I have tested this item
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-01-05 12:28:11 |
Closed_By | ⇒ | rdeutz |
@infograf768 please test