Module Styles are applied for templates containing "-" in their name
Labels |
Added:
?
|
@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!
Assigned to @GODFATHER0054 - good luck :)
@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.
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.
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
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.
The field is NOT in an xml file it is directly in administrator\components\com_templates\tmpl\template\default_modal_copy_body.php
Oh, I see. Thanks.
It probably should be extracted into an xml
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.
@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.
@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
Sure, and I agree. Only am thinking if there are maybe some B/C aspects.
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
So I might have ignored that at that time.
So we can safely add a validation for it in J4, right?
yes
@joomdonation Go for it please.
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
I'm open for both, the latter (make it work with "-" I would prefer for private reasons ;-) )
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.
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.
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.
agreed - please make a pr
Agree too.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-05-25 05:47:57 |
Closed_By | ⇒ | joomdonation |
Will you give me chance to do this ?