jimlee1982 / oauth

Automatically exported from code.google.com/p/oauth
0 stars 0 forks source link

php: improved split_header implementation #163

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Not really a defect, but the function could be made significantly faster (~
3x) by using preg_match_all and more optimal logic:

    $params = array();
    if
(preg_match_all('/('.($only_allow_oauth_parameters?'oauth_':'').'[a-z_-]*)=(:?"(
[^"]*)"|([^,]*))/',
$header, $matches)) {
        foreach ($matches[1] as $i => $h) {
            $params[$h] =
isset($matches[3][$i])?$matches[3][$i]:$matches[4][$i];
        }
        if (isset($params['realm'])) {
            unset($params['realm']);
        }
    }
    return $params;

Original issue reported on code.google.com by tjerk.me...@gmail.com on 7 May 2010 at 2:47

GoogleCodeExporter commented 8 years ago
Interesting change. I take it you have tested this against the unit tests and 
that they all still pass?

Original comment by morten.f...@gmail.com on 7 May 2010 at 3:24

GoogleCodeExporter commented 8 years ago
Ah, you guys have unit tests huh? Good, let me try and find them ;-)

Original comment by tjerk.me...@gmail.com on 7 May 2010 at 3:33

GoogleCodeExporter commented 8 years ago
Yup, if you do a checkout of the php-library from 
http://oauth.googlecode.com/svn/code/php/ you should be 
able to run "phpunit --config OAuthTests.xml"..

Original comment by morten.f...@gmail.com on 7 May 2010 at 3:35

GoogleCodeExporter commented 8 years ago
Took me 20 minutes to download phpunit, but managed to pass the test cases with 
some
alterations:

  public static function split_header($header, $only_allow_oauth_parameters = true) {
    $params = array();
    if
(preg_match_all('/('.($only_allow_oauth_parameters?'oauth_':'').'[a-z_-]*)=(:?"(
[^"]*)"|([^,]*))/',
$header, $matches)) {
      foreach ($matches[1] as $i => $h) {
        $params[$h] =
OAuthUtil::urldecode_rfc3986(empty($matches[3][$i])?$matches[4][$i]:$matches[3][
$i]);
      }
      if (isset($params['realm'])) {
        unset($params['realm']);
      }
    }
    return $params;
  }

Original comment by tjerk.me...@gmail.com on 7 May 2010 at 5:09

GoogleCodeExporter commented 8 years ago
Any updates? :)

Original comment by tjerk.me...@gmail.com on 26 May 2010 at 3:24

GoogleCodeExporter commented 8 years ago
Hi tjerk. 
Sorry, I'm busy with a huge university assignment. I just applied the patch, 
ran the unit tests myself and then 
committed the code. So as per revision 1212 your code is now in the repository. 
Thanks!
-Morten

Original comment by morten.f...@gmail.com on 28 May 2010 at 6:59

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
<r>

Original comment by B5332673 on 29 Jul 2013 at 6:04