From 5f383ff1b1c1d0a30bc79a56c69267d5c10bef30 Mon Sep 17 00:00:00 2001 From: selead Date: Sat, 25 Jun 2011 12:36:25 +0400 Subject: [PATCH 1/3] fix content length for oauth 1.0 --- lib/oauth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/oauth.js b/lib/oauth.js index e4071809..8ee56cee 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -325,7 +325,7 @@ exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_toke post_body= querystring.stringify(extra_params); } - headers["Content-length"]= post_body ? post_body.length : 0; //Probably going to fail if not posting ascii + headers["Content-length"]= post_body ? Buffer.byteLength(post_body) : 0; headers["Content-Type"]= post_content_type; var path; From 7e2aa8cfbed3e8194d0525fd2899a8255676c436 Mon Sep 17 00:00:00 2001 From: ciaranj Date: Sat, 25 Jun 2011 21:37:21 +0100 Subject: [PATCH 2/3] Adding test for character encoding / body length issue --- tests/oauth.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/oauth.js b/tests/oauth.js index e05907b8..22c687b1 100644 --- a/tests/oauth.js +++ b/tests/oauth.js @@ -306,6 +306,36 @@ vows.describe('OAuth').addBatch({ } }, 'if the post_body is a string' : { + "and it contains non ascii (7/8bit) characters" : { + "the content length should be the byte count, and not the string length" : function(oa) { + var testString= "Tôi yêu node"; + var testStringLength= testString.length; + var testStringBytesLength= Buffer.byteLength(testString); + assert.notEqual(testStringLength, testStringBytesLength); // Make sure we're testing a string that differs between byte-length and char-length! + + var op= oa._createClient; + try { + var callbackCalled= false; + oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) { + assert.equal(headers["Content-length"], testStringBytesLength); + return { + write: function(data){ + callbackCalled= true; + assert.equal(data, testString); + }, + on: function() {}, + end: function() { + } + }; + } + var request= oa.post("http://foo.com/blah", "token", "token_secret", "Tôi yêu node") + assert.equal(callbackCalled, true); + } + finally { + oa._createClient= op; + } + } + }, "and no post_content_type is specified" : { "It should be written as is, with a content length specified, and the encoding should be set to be x-www-form-urlencoded" : function(oa) { var op= oa._createClient; From d66ed8ad3244b8318b2f1fe5cf39601fd1073417 Mon Sep 17 00:00:00 2001 From: ciaranj Date: Sat, 25 Jun 2011 21:39:31 +0100 Subject: [PATCH 3/3] Updating readme and bumping version number for future release --- Readme.md | 7 ++----- package.json | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index dd4f09ca..5f097b2b 100644 --- a/Readme.md +++ b/Readme.md @@ -6,14 +6,11 @@ Tested against Twitter (http://twitter.com), term.ie (http://term.ie/oauth/examp Also provides rudimentary OAuth2 support, tested against facebook connect and github. For more complete usage examples please take a look at connect-auth (http://github.com/ciaranj/connect-auth) -If you're running a node.js version more recent than 0.4 then you will need to use a version of node-oauth greater than or equal to 0.9.0. -If you're running a node.js version in the 0.2x stable branch, then you will need to use version 0.8.4. - -Please be aware that when moving from 0.8.x to 0.9.0 there are no major API changes your, I've bumped the semi-major version element -so that I can release fixes to the 0.8.x stream if problems come out. Change History ============== + +* 0.9.2 - Correct content length calculated for non-ascii post bodies (Thanks selead) * 0.9.1 - Added support for automatically following 302 redirects (Thanks neyric) Added support for OAuth Echo (Thanks Ryan LeFevre). Improved handling of 2xx responses (Thanks Neil Mansilla). * 0.9.0 - Compatibility fixes to bring node-oauth up to speed with node.js 0.4x [thanks to Rasmus Andersson for starting the work ] * 0.8.4 - Fixed issue #14 (Parameter ordering ignored encodings). Added support for repeated parameter names. Implements issue #15 (Use native SHA1 if available, 10x speed improvement!). Fixed issue #16 (Should use POST when requesting access tokens.). Fixed Issue #17 (OAuth2 spec compliance). Implemented enhancement #13 (Adds support for PUT & DELETE http verbs). Fixes issue #18 (Complex/Composite url arguments [thanks novemberborn]) diff --git a/package.json b/package.json index 22e066e6..21b89651 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "oauth" , "description" : "Library for interacting with OAuth 1.0, 1.0A, 2 and Echo. Provides simplified client access and allows for construction of more complex apis and OAuth providers." -, "version" : "0.9.1" +, "version" : "0.9.2" , "directories" : { "lib" : "./lib" } , "main" : "index.js" , "author" : "Ciaran Jessup "