J7mbo / twitter-api-php

The simplest PHP Wrapper for Twitter API v1.1 calls
MIT License
1.82k stars 800 forks source link

URL decode GET parameters before adding to oAuth - fixes #111 #112

Closed glenscott closed 9 years ago

glenscott commented 9 years ago

GET parameters that have been URL encoded need to be decoded before adding to oAuth.

glenscott commented 9 years ago

Using the example from @gitboss listed here https://github.com/J7mbo/twitter-api-php/issues/111

$getfield = '?q=' . urlencode($query) . "&rpp=100" . ($max_id ? "&since_id=" . $max_id : "") ;

This query is correctly URL encoding the query parameter, so we must be sure to decode it before assembling the oAuth base string.

J7mbo commented 9 years ago

Hi Glen, thanks for this - could you also add a forward slash to the / $search and $replace vars in setGetField()? This is so we can actually just use ?q=http://www.google.com in the query.

Line 139/140:

    $search = array('#', ',', '+', ':', '/');
    $replace = array('%23', '%2C', '%2B', '%3A', '%2F');

If you can add that, I'll merge and also write a test for it.

glenscott commented 9 years ago

Actually, I realised I didn't push my complete fix. The URL logic in setGetFields has been removed -- you need to amend your documentation to make it cleat that any GET parameters should be urlencoded before before being passed to this function.

J7mbo commented 9 years ago

Actually, the aim was for the user not to have to encode anything before passing the data to setGetField(). They should just be able to type the query in plain english and the lib would take care of the rest (most user friendly imho anyway :-))

glenscott commented 9 years ago

Ok, no worries. Let me correct the encoding logic in setGetFields.

glenscott commented 9 years ago

Ok, I've used the urlencode function to cope with any non-standard characters in query parameters, rather than just '#', ',', '+', ':', '/'

J7mbo commented 9 years ago

Looks like the testStatusesRetweetsOfMe() is failing now, thanks travis!

glenscott commented 9 years ago

would you like me to look into this failing test?

J7mbo commented 9 years ago

@glenscott It's alright I'm taking a look atm, if I find anything I'll let you know :+1: