?
avatar jos-webservices
jos-webservices
9 Mar 2021

Steps to reproduce the issue

  • copy the Cassiopeia template and name the new template something conatining a "-", e.g. "cassio-peia"
  • make the new template style (e.g. "cassio-peia - Default") your new default
  • try to apply "Module Styles" of this template - it will not work

Expected result

Module Styles are applied for templates containing "-" in their name

Actual result

Module Styles are not applied
grafik

System information (as much as possible)

grafik

avatar jos-webservices jos-webservices - open - 9 Mar 2021
avatar joomla-cms-bot joomla-cms-bot - change - 9 Mar 2021
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 9 Mar 2021
avatar GODFATHER0054
GODFATHER0054 - comment - 11 Mar 2021

Will you give me chance to do this ?

avatar drmenzelit
drmenzelit - comment - 11 Mar 2021

@GODFATHER0054 you don't need to ask for permission, you can provide a pull request for this issue, if you want. It will then be reviewed and tested, and hopefully accepted :-)
Thank you for contributing!

avatar chmst
chmst - comment - 12 Mar 2021

Assigned to @GODFATHER0054 - good luck :)

avatar richard67
richard67 - comment - 13 Mar 2021

@jos-webservices If you attempt to copy a template, there is a text shown below the field where you enter the new name, and this text tells to use only letters, numbers and underscores.

2021-03-13_1

This means you shall not use dashes or hyphens "-".

So from my point of view the bug is that you can save the new template with a name which contains a "-" despite of what the text says, or the text is wrong.

The same applies to Joomla 3 by the way, you get the same text there, telling you shall use only letters, numbers and underscores.

@GODFATHER0054 Please check this comment, too, before making a fix which goes the wrong way.

avatar brianteeman
brianteeman - comment - 13 Mar 2021

So from my point of view the bug is that you can save the new template with a name which contains a "-" despite of what the text says, or the text is wrong.

The text is correct. The problem is that there is no filtering or checks on the input. A simple pattern of [A-Za-z0-9_] would be correct but it will need to have some form of error message as well

avatar richard67
richard67 - comment - 13 Mar 2021

The text is correct. The problem is that there is no filtering or checks on the input. A simple pattern of [A-Za-z0-9_] would be correct

Then my first assumption was right, and we need to fix that in this way.

but it will need to have some form of error message as well

When using a validation rule or creating a new validation rule for that, and add a validation=... for that field in the form XML, the error message will always be "Invalid field so-and-so", with "so-and-so" being the field title. I think that's sufficient.

avatar brianteeman
brianteeman - comment - 13 Mar 2021

The field is NOT in an xml file it is directly in administrator\components\com_templates\tmpl\template\default_modal_copy_body.php

avatar richard67
richard67 - comment - 13 Mar 2021

Oh, I see. Thanks.

avatar brianteeman
brianteeman - comment - 13 Mar 2021

It probably should be extracted into an xml

avatar joomdonation
joomdonation - comment - 13 Mar 2021

We actually perform server side validation already https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_templates/src/Controller/TemplateController.php#L153-L154

However, we are using cmd filter for $newName, so it accepts other characters such as .,-

I haven't tested but I think changes that two lines of code to the below code should help

$newNameRaw = $this->input->get('new_name', null, 'string');
$newName    = preg_replace('#[^a-zA-Z0-9_]#', '', $newNameRaw);

The two names will then be compared at https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_templates/src/Controller/TemplateController.php#L189 and will throw an error to prevent the template from being copied.

avatar richard67
richard67 - comment - 13 Mar 2021

@joomdonation That makes sense to me and should work. If it's the right way to fix it: I don't know.

Funny detail: On my private website I use a copy of the Protostar template, which has a "-" in its name, so either the description text telling to use only characters, numbers and underscores was not there at this time, or I have ignored it. So when I migrate my site to J4 I'll have to fix that.

avatar joomdonation
joomdonation - comment - 13 Mar 2021

@richard67 I don't work with templates, so I don't know, too. I just propose code because we display the message Letters, numbers and underscore only

avatar richard67
richard67 - comment - 13 Mar 2021

Sure, and I agree. Only am thinking if there are maybe some B/C aspects.

avatar brianteeman
brianteeman - comment - 13 Mar 2021

I have looked into the history and from day this copy template functionality was added in Joomla 2.5 there was the description about no dashes https://developer.joomla.org/joomlacode-archive/issue-28472.html

avatar richard67
richard67 - comment - 13 Mar 2021

So I might have ignored that at that time.

So we can safely add a validation for it in J4, right?

avatar brianteeman
brianteeman - comment - 13 Mar 2021

yes

avatar richard67
richard67 - comment - 13 Mar 2021

@joomdonation Go for it please.

avatar brianteeman
brianteeman - comment - 13 Mar 2021

OR we spend time working out how to fix the identiified issue here and any others that may appear by allowing the -

I suspect that the reason we dont allow it was because it was "too hard" to find out why the - broke things

avatar richard67
richard67 - comment - 13 Mar 2021

I'm open for both, the latter (make it work with "-" I would prefer for private reasons ;-) )

avatar jos-webservices
jos-webservices - comment - 13 Mar 2021

I have looked into the history and from day this copy template functionality was added in Joomla 2.5 there was the description about no dashes https://developer.joomla.org/joomlacode-archive/issue-28472.html

Sorry for ignoring that and bringing up this issue instead. I think input validation for the copy name would be the right approach.

avatar jos-webservices
jos-webservices - comment - 14 Mar 2021

I suspect that the reason we dont allow it was because it was "too hard" to find out why the - broke things

Didn't have a look at the code yet, however from checking why it didn't work for me: I suspect the reason for not allowing "-" is the way the module style is saved in the DB. It is saved as [TemplateName]-[ModuleStyle]. Now, if TemplateName has a "-", dividing the two becomes difficult.

avatar joomdonation
joomdonation - comment - 15 Mar 2021

You are right. The module style is saved in [TemplateName]-[ModuleStyle] format, see https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Form/Field/ChromestyleField.php#L159 for reference

It is then processed here https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Helper/ModuleHelper.php#L193-L195

Basically, we are using - character to separate between template and module style and it causes this restriction. For now, I think it is too late to change this separator, so the best thing we can do is adding validation to prevent creating template which contains "-" in the name. If we all agree with that, I can make a PR later.

avatar brianteeman
brianteeman - comment - 20 May 2021

agreed - please make a pr

avatar richard67
richard67 - comment - 20 May 2021

Agree too.

avatar joomdonation joomdonation - close - 25 May 2021
avatar joomdonation
joomdonation - comment - 25 May 2021

Please test PR #34196 . Thanks.

avatar joomdonation joomdonation - change - 25 May 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-05-25 05:47:57
Closed_By joomdonation

Add a Comment

Login with GitHub to post a comment