?
avatar AndyGaskell
AndyGaskell
7 Feb 2017

This is not really a serious issue I think, just catching a corner case of user input really.

Steps to reproduce the issue

  1. Go to the "administrator" area in Joomla
  2. Click on "Content" -> "Articles" -> "Add new article"
  3. In the "Articles: Edit" screen, enter a title.
  4. Click on the "Publishing" tab.
  5. Add an extra zero to the time date value "Created Date", so, for example change it from "2017-02-07 12:53:04" to "2017-02-07 012:53:04"

Expected result

I was expecting some client side validation to alert me of the invalid input, or perhaps some server side validation.

Actual result

I get an error message saying
DateTime::__construct(): Failed to parse time string (2017-02-07 012:25:10) at position 11 (0): Unexpected character

error_0_datetime_construct failed_to_parse_time_string 2017-02-07_102_53_04 at_position_11 1 unexpected_character-_2017-02-07_12 56 00

System information (as much as possible)

PHP Built On Linux 2.6.32-642.6.2.el6.x86_64 #1 SMP Wed Oct 26 06:52:09 UTC 2016 x86_64
Database Version 5.6.34
Database Collation latin1_swedish_ci
Database Connection Collation utf8mb4_general_ci
PHP Version 7.0.15
Web Server Apache
WebServer to PHP Interface cgi-fcgi
Joomla! Version Joomla! 3.6.5 Stable [ Noether ] 1-December-2016 22:46 GMT
Joomla! Platform Version Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
User Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0
..and also...
PHP Built On Linux hp-i5 4.8.0-34-generic #36-Ubuntu SMP Wed Dec 21 17:24:18 UTC 2016 x86_64
Database Version 5.7.17-0ubuntu0.16.10.1
Database Collation latin1_swedish_ci
Database Connection Collation utf8mb4_general_ci
PHP Version 7.0.8-3ubuntu3
Web Server Apache/2.4.18 (Ubuntu)
WebServer to PHP Interface apache2handler
Joomla! Version Joomla! 3.6.4 Stable [ Noether ] 21-October-2016 16:33 GMT
Joomla! Platform Version Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
User Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0

Additional comments

This is the same for the "Start Publishing" and "Finish Publishing" fields, and is also the same in the Joomla front end.

I'll try and come up with a fix and a pull request.

avatar AndyGaskell AndyGaskell - open - 7 Feb 2017
avatar joomla-cms-bot joomla-cms-bot - change - 7 Feb 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 7 Feb 2017
avatar Bakual
Bakual - comment - 7 Feb 2017

JS validation certainly would be nice.
I think it would also make sense to catch the error and display a nice error message instead (or at least a generic "invalid input" message)

avatar tonypartridge
tonypartridge - comment - 7 Feb 2017

For JS we would need to have a rather complex function, what about handling this on save and outputting an error message using php?

Not only that, but should this be user input adjustable? Shouldn't it be selected from a calendar / time selector?

avatar Bakual
Bakual - comment - 7 Feb 2017

For JS we would need to have a rather complex function, what about handling this on save and outputting an error message using php?

Agreed. JS may be complex especially with different rules for different languages.

Not only that, but should this be user input adjustable?

Certainly yes. It's much faster to input a date using the keyboard than searching the date with a calendar popup. Especially if we're speaking about eg a day of birth.

avatar tonypartridge
tonypartridge - comment - 7 Feb 2017

Exactly my thoughts too @Bakual easy enough to do for 1 language but multiple.... eek.

Good point, I was just thinking more of date saved etc.

So we need to look at PHP side validation.

avatar Bakual
Bakual - comment - 7 Feb 2017

I haven't had the time yet to debug this, but my first guess would be this line:
https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/form/form.php#L1288 and https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/form/form.php#L1321
If that error can be catched (looks like an exception to me), then we can enqueue at least a message instead of that error. However that's only the filter here, I never tried what happens when you return "false" in the filtering step. I don't think it will create a validation error.
So I think we'd need an additional formrule which uses a similar approach?

avatar tonypartridge
tonypartridge - comment - 7 Feb 2017

I was thinking serverside validation rule for the field? Since catching the error at that point is too late I believe.

avatar Bakual
Bakual - comment - 8 Feb 2017

As a partial solution, catching the error during filtering and showing a warning instead of exploding.
#13974

avatar franz-wohlkoenig franz-wohlkoenig - change - 30 Mar 2017
Category com_content
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 5 Apr 2017

@Bakual close this Issue because #13974?


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

avatar franz-wohlkoenig franz-wohlkoenig - change - 5 Apr 2017
Status New Confirmed
avatar Bakual
Bakual - comment - 5 Apr 2017

If people (eg @AndyGaskell) are fine with that solution, this can be closed.

avatar brianteeman
brianteeman - comment - 21 May 2017

As it has been 6 weeks since the last comment I am closing this on the assumption that the pull request was ok for everyone. it can always be reopened if required

avatar brianteeman brianteeman - change - 21 May 2017
Status Confirmed Closed
Closed_Date 0000-00-00 00:00:00 2017-05-21 15:02:00
Closed_By brianteeman
avatar brianteeman brianteeman - close - 21 May 2017
avatar AndyGaskell
AndyGaskell - comment - 22 May 2017

Sorry I missed this earlier, @Bakual, that fix in #13974 looks good, thank you.

Add a Comment

Login with GitHub to post a comment