Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isBase64 function problem which added in version 7.0.1 #667

Closed
tigran-m-dev opened this issue Aug 15, 2018 · 5 comments
Closed

isBase64 function problem which added in version 7.0.1 #667

tigran-m-dev opened this issue Aug 15, 2018 · 5 comments
Labels
difficulty: easy fix is easy in difficulty status: work in progress Twilio or the community is in the process of implementing type: bug bug in the library

Comments

@tigran-m-dev
Copy link

Issue Summary

A summary of the issue and the environment in which it occurs. If suitable, include the steps required to reproduce the bug. Please feel free to include screenshots, screencasts, code examples.

Steps to Reproduce

  1. Try to send as an attachment text file which contains for example \n
  2. Before setContent call convert your attachment as base64

After all this process the isBase64 function will return false, because it not passed ctype_print

Technical details:

This issue in version 7.0.1 and came from merge with number #618

my suggestion to change isBase64 function something like this

private function isBase64($string) {
   $decoded_data = base64_decode($string, true);
   $encoded_data = base64_encode($decoded_data);
   if ($encoded_data != $string) return false;
   else{ 
        $decoded_data=str_ireplace("\t","",$decoded_data);
        $decoded_data=str_ireplace("\n","",$decoded_data);
        $decoded_data=str_ireplace("\r","",$decoded_data);
        if (!ctype_print($decoded_data)) 
            return false;
        }
   
   return true;
}

so new part is this

$decoded_data=str_ireplace("\t","",$decoded_data);
$decoded_data=str_ireplace("\n","",$decoded_data);
$decoded_data=str_ireplace("\r","",$decoded_data);
@tigran-m-dev
Copy link
Author

@thinkingserious Could you please check this.

@martijnmelchers
Copy link
Contributor

Why would an attachment only be \n though?

@tigran-m-dev
Copy link
Author

@martijnmelchers not only \n. For example if it is contained some formatting text with \n
like this:

some text
some additional text

in this situation ctype_print will return false

@tigran-m-dev
Copy link
Author

Just run this simple check

var_dump(ctype_print('some text
some additional text'));

thinkingserious added a commit that referenced this issue Aug 15, 2018
@thinkingserious thinkingserious added type: bug bug in the library status: work in progress Twilio or the community is in the process of implementing difficulty: easy fix is easy in difficulty labels Aug 15, 2018
@thinkingserious
Copy link
Contributor

thinkingserious commented Aug 15, 2018

Nice find @developer-devPHP!

Please allow us to send you some swag by filling out this form.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: easy fix is easy in difficulty status: work in progress Twilio or the community is in the process of implementing type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

3 participants