Skip to content
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

Modal titles should be escaped properly #7845

Merged
merged 2 commits into from
Sep 14, 2015
Merged

Modal titles should be escaped properly #7845

merged 2 commits into from
Sep 14, 2015

Conversation

dgrammatiko
Copy link
Contributor

This should take care titles that contain quotes

Test

Make sure that nothing breaks

@@ -191,7 +191,7 @@
'bootstrap.renderModal',
'collapseModal',
array(
'title' => JText::_('COM_BANNERS_BATCH_OPTIONS'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgt41 Can't we just use this here:

JText::_('COM_BANNERS_BATCH_OPTIONS', true),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, did that!

@infograf768
Copy link
Member

This does not work here: it adds a slash before the single quote:
For example, when editing a single article menu item and using:
COM_CONTENT_CHANGE_ARTICLE="Sélectionner ou changer l'article"
The modal now loads OK but I get, for its title
screen shot 2015-09-10 at 08 16 06

@infograf768
Copy link
Member

  • @zero-24 is correct concerning user notes. The plural should not be taken off or we get:
    screen shot 2015-09-10 at 08 23 20

@infograf768
Copy link
Member

Found a not-so-elegant solution in the layout...
<h3><?php echo str_replace("\'", "'", $params['title']); ?></h3>

@Bakual
Copy link
Contributor

Bakual commented Sep 10, 2015

That looks wrong. There must be a better way.

@infograf768
Copy link
Member

That looks wrong. There must be a better way.

I hope so... that's why I wrote a "not-so-elegant" solution...

@Fedik
Copy link
Member

Fedik commented Sep 10, 2015

just curious, what wrong with $this->escape($params['title']) ?

@infograf768
Copy link
Member

that would work indeed

@infograf768
Copy link
Member

@dgt41
The new much simpler change works fine!

@dgrammatiko
Copy link
Contributor Author

Hi, some further infos here, the problem comes from this line:
https://github.com/joomla/joomla-cms/blob/staging/layouts/joomla/modal/main.php#L73
Following @infograf768 solution (reversed) solves the problem without the need to add all those true switches to each JText.
Also this is 100% B/C

@infograf768
Copy link
Member

One tester more to get this merged

@Bakual
Copy link
Contributor

Bakual commented Sep 10, 2015

Instead of using a custom preg_replace, please use the native function addslashes().
And then test also with double quotes " and backslashes \ as those will be escaped by this method as well.
I tested it locally and it worked fine.

@infograf768
Copy link
Member

@Bakual
Agree with addslashes()

@dgrammatiko
Copy link
Contributor Author

@Bakual @infograf768 done!

@infograf768
Copy link
Member

OK here!

@roland-d
Copy link
Contributor

All looking OK here. Setting to RTC as we have 2 successful tests.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7845.

@ggppdk
Copy link
Contributor

ggppdk commented Sep 17, 2015

I think @Fedik 's suggestion
$this->escape()
which is:
htmlspecialchars(..., ENT_COMPAT, 'UTF-8');

is the prefered way to encode HTML Tag parameters:
so this should better
$iframeAttributes['name'] = htmlspecialchars($params['title'], ENT_COMPAT, 'UTF-8');

which will

  • encode double quotes and other special characters,
  • it will skip single quotes
  • it will consider UTF-8 characters and not encode them

i mean it is used inside Joomla and extensions code extensively to encode HTML Tag parameters, why this is an exception ?

@dgrammatiko
Copy link
Contributor Author

@ggppdk Georgeif you think that the current merged solution is inadequate please do a new pr!

@ggppdk
Copy link
Contributor

ggppdk commented Sep 17, 2015

i am not sure )) that is why my post was a question
i am often wrong too ))

i noted that in other places we are escaping the value of an HTML tag parameters in different way

@dgrammatiko
Copy link
Contributor Author

The thing here is that the string has to be escaped for JavaScript not for html, so I'm not sure if your suggestion will work. Currently I'm not at my desk so I cannot test it....

@ggppdk
Copy link
Contributor

ggppdk commented Sep 17, 2015

addslashes will work for javascript
i am asking if it can break some UTF-8 characters making some words appear mispelled ?
from what i read if it is given a valid UTF-8 string, then the string will not break

@Bakual
Copy link
Contributor

Bakual commented Sep 18, 2015

it will skip single quotes

The only issue was the single quote which needs to be escaped for JS. Otherwise JS thinks the string ends and the code is broken. So your suggestion would not work.

@ggppdk
Copy link
Contributor

ggppdk commented Sep 18, 2015

  • you only need to escape (at least) double quotes to get parseable HTML
    <iframe name="text_with_escaped_double_quotes" ...>
  • and for valid HTML (not just parsable) use on the HTML Tag parameter values
    htmlspecialchars(..., ENT_COMPAT, 'UTF-8');

but then i see that HTML created by the ...\modal.php

  • is used in JS code that assumes that single quotes are escaped

SORRY i missed that !, so yes you are right, (as i said i am often wrong)

  • single quotes need to be escaped (for current JS code to work)

just a note, i think it would be best that HTML creation in template is more consistent

  1. inside templates files just create valid HTML
  2. do escaping of single quotes at the place that PHP code is creating the JS code
  • thus avoid workarounds like this, and also if modal.php is updated in the future, nothing will break
    e.g. if some adds a single quote anywhere, not just inside the HTML parameter values, but anywhere
  • anyway current solution works and is B/C, no need to change something

@dgt41
thanks for your contribution, i am sorry i meant nothing wrong about your works

i wish i could contribute just i am involved in with 2 web softwares with too large code base
i need to update my own code and removed deprecated stuff

a reason for the comment, is that i remember my modals sometimes being broken (i don't remember why), and i ended up replacing them with jQuery modals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants