J4 Issue ?
avatar astridx
astridx
5 Jan 2018

Steps to reproduce the issue

Install Joomla version 4 and call the super user
admin&
admin with an following ampersand

Expected result

The user should be saved with the name
admin&
admin with an following ampersand or there should be a warning or the the user should not be saved

Actual result

The user is saved with the user name admin. The ampersand is cut off.

System information (as much as possible)

Current Joomla! 4.0.0-dev Development [ Amani ]

avatar astridx astridx - open - 5 Jan 2018
avatar joomla-cms-bot joomla-cms-bot - change - 5 Jan 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 5 Jan 2018
avatar brianteeman
brianteeman - comment - 5 Jan 2018

The same problem exists for passwords - reported elsewhere just add this to that issue.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 5 Jan 2018
avatar franz-wohlkoenig franz-wohlkoenig - change - 5 Jan 2018
Category com_users
avatar franz-wohlkoenig franz-wohlkoenig - change - 5 Jan 2018
Status New Discussion
Build staging 4.0-dev
avatar astridx
astridx - comment - 5 Jan 2018

@brianteeman
I am not sure if it is the same issue. We do not allow user names with an ampersand up to now. If you create an user with an ampersand in the user name via user manager, you see a warning.
This warning is because of JOOMLA/media/system/js/fields/validate.min.js

So we should decide if we want allow user names with special characters (RegExp("[<|>|"|'|%|;|(|)|&]", "i")).

avatar brianteeman brianteeman - labeled - 25 Mar 2018
avatar brianteeman
brianteeman - comment - 8 Jun 2018

Testing this again
Creating a user in the backend fails with the correct error message

Creating a user at installation allows you to create a user with an & and it is stored in the db with an &
However that user cannot log in

So for me the error is in the installer and it not using the same filtering as the rest of joomla

avatar brianteeman
brianteeman - comment - 26 Jun 2018

In fact looking closer the installer uses no filtering at all

avatar brianteeman brianteeman - change - 26 Jun 2018
Title
[4.0] Create an user with the username admin& (ampersand ) creates an user with the name admin (without ampersand )
[4.0] Installer - username validation
avatar brianteeman brianteeman - edited - 26 Jun 2018
avatar brianteeman
brianteeman - comment - 12 Aug 2018

The problem is that users are validated in the installer with JOOMLA/media/system/js/fields/validate.min.js
const regex = new RegExp('[<|>|"|\'|%|;|(|)|&]', 'i');
But in the admin they are validated with a completely different regex

if (preg_match('#[<>"\'%;()&\\\\]|\\.\\./#', $this->username) || strlen(utf8_decode($this->username)) < 2

It looks like the email is validated differently as well

avatar dgrammatiko
dgrammatiko - comment - 12 Aug 2018

The problem is that users are validated in the installer with JOOMLA/media/system/js/fields/validate.min.js
const regex = new RegExp('[<|>|"|'|%|;|(|)|&]', 'i');
But in the admin they are validated with a completely different regex

Just use the HTML5 pattern in the XML and use the same regex. That should fix the inconsistency (assuming that the pattern is working correctly otherwise blame me and I'll get it fixed)

avatar brianteeman
brianteeman - comment - 12 Aug 2018

I can do that (and agree) but then we have multiple unused regex in multiple places

Remember I wanted to do #18995

avatar brianteeman
brianteeman - comment - 12 Aug 2018

Plus the error message from an html5 pattern isn't very good as it doesnt tell you why it fails

chrome_2018-08-12_21-18-25

I assume though that it is automatically translated according to the browser language

avatar ggppdk
ggppdk - comment - 12 Aug 2018

Just use the HTML5 pattern in the XML and use the same regex

Plus the error message from an html5 pattern isn't very good as it doesnt tell you why it fails

text field layout now has ...

$attributes = array(
	...
	strlen($hint) ? 'placeholder="' . htmlspecialchars($hint, ENT_COMPAT, 'UTF-8') . '"' : '',
	...
	!empty($pattern) ? 'pattern="' . $pattern . '"' : '',
);
?>

We could try adding support 1 new attribute to the XML files
error_hint="..."

$attributes = array(
	...
	strlen($hint) ? 'placeholder="' . htmlspecialchars($hint, ENT_COMPAT, 'UTF-8') . '"' : '',
	...
	!empty($pattern) ? 'pattern="' . $pattern . '"' : '',
	!empty($error_hint) ? 'oninvalid="setCustomValidity(\'' . htmlspecialchars($error_hint, ENT_QUOTES, 'UTF-8') . '\');" ' : '',
	!empty($error_hint) ? 'oninput="setCustomValidity(\'\');" ' : '',
);
?>
avatar ggppdk
ggppdk - comment - 12 Aug 2018

I see a new attribute for XML definition of text field already exists in J4 and it is called ?
'validationtext'

thus the above can be used ?

avatar ggppdk
ggppdk - comment - 12 Aug 2018

Thus i suggest adding attributes
pattern
validationtext

to the password field like they exist in the text field

[EDIT]
and to any other fields that can possibly use them (if there are any other such fields)

avatar dgrammatiko
dgrammatiko - comment - 12 Aug 2018

@ggppdk I've already implemented the validationtext because I thought it will be handy. I guess I should have implemented one field as a showcase as it's now pretty hard to figure out without reading the code. Ooops sorry...

avatar brianteeman
brianteeman - comment - 12 Aug 2018

@dgrammatiko give me an example and I will see what I can do. This is especially important for accessibility as it will allow us to have inline error messages instead of having them out of context in an alert

avatar dgrammatiko
dgrammatiko - comment - 12 Aug 2018

@brianteeman the xml should be like (you'll need to use the right regex though):
screenshot 2018-08-12 at 23 29 23

and then it should just work:
screenshot 2018-08-12 at 23 29 12

avatar brianteeman
brianteeman - comment - 12 Aug 2018

the regex is no problem ;)

as for the validationtext - does it support Jtext?

avatar dgrammatiko
dgrammatiko - comment - 12 Aug 2018

@brianteeman that part was never implemented. in libraries/src/Form/FormField.php line 1002 change it to 'validationtext' => Text::_($this->validationtext),. That should be enough to introduce the translations
screenshot 2018-08-12 at 23 51 27

avatar brianteeman
brianteeman - comment - 12 Aug 2018

Ok well I can see what I am doing tomorrow

avatar Quy
Quy - comment - 26 Feb 2019

Fixed with PR #23918 in J3.

avatar brianteeman
brianteeman - comment - 26 Feb 2019

@Quy that might not fix the issue here as the installer for j4 is almost completely different code

avatar alikon
alikon - comment - 26 Feb 2019

imho #23918 is not enough we lack the client side validation
but in the meantime test the server side one 😄 #24024

avatar dgrammatiko
dgrammatiko - comment - 26 Feb 2019

@alikon @brianteeman the front end part was already fixed in
#21584 but then that PR was closed. FWIW my intension when I did patch the validation.js to deal with the pattern attribute was to move to HTML5 validation and also have one regex per field (php or js). Obviously converting all the forms is kinda big task but honestly I hope someone will do it for J4. Brian already showcased what needs to be done, it's not hard but it's a big task

avatar Quy Quy - close - 11 Dec 2019
avatar Quy Quy - change - 11 Dec 2019
Status Discussion Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2019-12-11 04:07:08
Closed_By Quy
avatar Quy
Quy - comment - 11 Dec 2019

Fixed with #23918 that has ported to J4.


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

Add a Comment

Login with GitHub to post a comment