? Success

User tests: Successful: Unsuccessful:

avatar piotrmocko
piotrmocko
30 Mar 2016

Pull Request for Issue # .

Summary of Changes

Filter raw JSON response, catch any PHP warnings and add them to error messages of JSON response.

It fixes case when there is a PHP warning in response. Now there will be no message displayed to the user, because parsing JSON response would fail.

Testing Instructions

  1. Enable error reporting
  2. Setup mailer in Joomla Global Configuration to fail SMTP TLS or SSL verification, e.g. security: none when it requires SSL
  3. JSON request would fail and there will be know message to the user.

You will get similar response:

<br />
<b>Warning</b>:  stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages
:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in <b>/libraries/vendor/phpmailer/phpmailer/class.smtp.php</b> on line 
<b>343</b><br />
{"success":true,"message":null,"messages":{"notice":["SMTP Error: Could not connect to SMTP host."],"error"
:["Test mail could not be sent."]},"data":false}
avatar piotrmocko piotrmocko - open - 30 Mar 2016
avatar piotrmocko piotrmocko - change - 30 Mar 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 30 Mar 2016
Labels Added: ?
avatar andrepereiradasilva
andrepereiradasilva - comment - 30 Mar 2016

the problem here, IMHO is the php warnings in phpmailer class.

In this case i think you're referring to https://github.com/joomla/joomla-cms/blob/staging/libraries/vendor/phpmailer/phpmailer/class.smtp.php#L334

which is the phpmailer SMTP class, so the warning if it's a problem it should be resolved by phpmailer team: https://github.com/PHPMailer/PHPMailer/issues

avatar piotrmocko
piotrmocko - comment - 30 Mar 2016

I agree that it could be resolved by PHP Mailer Team. But before that or if there will be any other php warning in the JSON response, user would not see any message and will be confused. He would think that send test email feature is not working and will be asking on forum, because we did not handle warnings

avatar mbabker
mbabker - comment - 30 Mar 2016

IMO an isolated fix like this for one JSON driven action is more a hack
than a fix. If you want to make sure all JSON based requests always give a
valid response in Joomla, you need to go deeper than fixing this single use
case.

On Wednesday, March 30, 2016, Piotr Moćko notifications@github.com wrote:

I agree that it could be resolved by PHP Mailer Team. But before that or
if there will be any other php warning in the JSON response, user would not
see any message and will be confused. He would think that send test email
feature is not working and will be asking on forum, because we did not
handle warnings


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#9676 (comment)

avatar andrepereiradasilva
andrepereiradasilva - comment - 30 Mar 2016

Not regarding this case in concrete. i can see the needing adding error messages in case there is no connection or any other problem in the ajax call.

avatar andrepereiradasilva
andrepereiradasilva - comment - 30 Mar 2016

ups mbabker already said that.

avatar piotrmocko
piotrmocko - comment - 30 Mar 2016

I will create some JS function in Joomla core.js to handle ajax response
filtering if you think that it would be enough.

I do not see any possibility to handle it globally in PHP before displaying
response.

This is also the case when it is needed, because after clicking Send test
email button there will be no reaction in user interface and no message
would be displayed like nothing had happened.

avatar andrepereiradasilva
andrepereiradasilva - comment - 30 Mar 2016
avatar piotrmocko
piotrmocko - comment - 30 Mar 2016

In most cases it is genereted by JResponseJson
https://github.com/joomla/joomla-cms/blob/staging/libraries/cms/response/json.php
And it would not be possible to strip out other output generated before

avatar brianteeman brianteeman - change - 30 Mar 2016
Category JavaScript
avatar andrepereiradasilva
andrepereiradasilva - comment - 31 Mar 2016

@piotrmocko if you apply this patch (#9685) you still have a problem with the php warning, right?

avatar piotrmocko
piotrmocko - comment - 31 Mar 2016

Yes, it would not help, as response output would not have a valid JSON and jQuery would fail.

I have been fighting with it for a long time in my Perfect Ajax Popup Contact Form.
The only possible way to handle PHP warnings in output or some other stuff thrown to the output by some bad coded system plugins is to filter JSON response before parsing it into object.

@nikosdion in his extensions is putting JSON response between hashes ###{"success:true,...}### and after receiving it, it is being stripped out, and any warning which would occur before or after response would not break handling this response.

avatar andrepereiradasilva
andrepereiradasilva - comment - 31 Mar 2016

@piotrmocko i think you can now close this one in favor of #9685

avatar piotrmocko piotrmocko - change - 1 Apr 2016
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2016-04-01 07:52:07
Closed_By piotrmocko
avatar piotrmocko piotrmocko - close - 1 Apr 2016

Add a Comment

Login with GitHub to post a comment