From 79c5abd09746b3ff87ef47e937af1b63ddb4f939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Fri, 11 Feb 2011 11:15:44 -0500 Subject: [PATCH 1/8] Fix warnings when running the test suite --- test/common.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/common.js b/test/common.js index 191182ee4..85308356b 100644 --- a/test/common.js +++ b/test/common.js @@ -24,3 +24,10 @@ global.p = function(val) { global.GENTLY = new Gently(); global.HIJACKED = GENTLY.hijacked; + +// Stupid new feature in node that complains about gently attaching too many +// listeners to process 'exit'. This is a workaround until I can think of a +// better way to deal with this. +if (process.setMaxListeners) { + process.setMaxListeners(Infinity); +} From 2934c84672baab3fc25b17da1b5d46495d57167a Mon Sep 17 00:00:00 2001 From: Nick Payne Date: Sun, 20 Feb 2011 11:57:47 +0000 Subject: [PATCH 2/8] catching typeof object in client escape method; adding relevant tests --- lib/mysql/client.js | 3 +++ test/simple/test-client.js | 2 ++ 2 files changed, 5 insertions(+) diff --git a/lib/mysql/client.js b/lib/mysql/client.js index a3e405fec..83a1cd0c9 100644 --- a/lib/mysql/client.js +++ b/lib/mysql/client.js @@ -178,6 +178,9 @@ Client.prototype.escape = function(val) { switch (typeof val) { case 'boolean': return (val) ? 'true' : 'false'; case 'number': return val+''; + // don't just return a toString outright incase it returns + // characters we need to treat later + case 'object': val = val.toString(); break; } val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function(s) { diff --git a/test/simple/test-client.js b/test/simple/test-client.js index e5d6e099c..aac53f682 100644 --- a/test/simple/test-client.js +++ b/test/simple/test-client.js @@ -365,6 +365,8 @@ test(function escape() { assert.equal(client.escape(false), 'false'); assert.equal(client.escape(true), 'true'); assert.equal(client.escape(5), '5'); + assert.equal(client.escape({foo:'bar'}), "'[object Object]'"); + assert.equal(client.escape([1,2,3]), "'1,2,3'"); assert.equal(client.escape('Super'), "'Super'"); assert.equal(client.escape('Sup\0er'), "'Sup\\0er'"); From 063d44b7f16e6ba7f6b2d1450ededd481175e76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 20 Feb 2011 14:14:52 +0100 Subject: [PATCH 3/8] Improve code clarity --- lib/mysql/client.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/mysql/client.js b/lib/mysql/client.js index 83a1cd0c9..b7d8f67f2 100644 --- a/lib/mysql/client.js +++ b/lib/mysql/client.js @@ -178,9 +178,10 @@ Client.prototype.escape = function(val) { switch (typeof val) { case 'boolean': return (val) ? 'true' : 'false'; case 'number': return val+''; - // don't just return a toString outright incase it returns - // characters we need to treat later - case 'object': val = val.toString(); break; + } + + if (typeof val === 'object') { + val = val.toString(); } val = val.replace(/[\0\n\r\b\t\\\'\"\x1a]/g, function(s) { From a270e695da041bdd28ba80f4693d317c8458d05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 20 Feb 2011 14:32:23 +0100 Subject: [PATCH 4/8] Drop sys/util compatibility The 'sys' module has been soft-renamed to 'util' in 0.4. --- lib/mysql/client.js | 4 ++-- lib/mysql/parser.js | 4 ++-- lib/mysql/query.js | 4 ++-- lib/mysql/sys.js | 6 ------ test/common.js | 4 ++-- 5 files changed, 8 insertions(+), 14 deletions(-) delete mode 100644 lib/mysql/sys.js diff --git a/lib/mysql/client.js b/lib/mysql/client.js index b7d8f67f2..f96fe2ab0 100644 --- a/lib/mysql/client.js +++ b/lib/mysql/client.js @@ -1,6 +1,6 @@ if (global.GENTLY) require = GENTLY.hijack(require); -var sys = require('./sys'), +var util = require('util'), Stream = require('net').Stream, auth = require('./auth'), Parser = require('./parser'), @@ -39,7 +39,7 @@ function Client(properties) { this[key] = properties[key]; } }; -sys.inherits(Client, EventEmitter); +util.inherits(Client, EventEmitter); module.exports = Client; Client.prototype.connect = function(cb) { diff --git a/lib/mysql/parser.js b/lib/mysql/parser.js index 32e5ed34e..0e9db9d79 100644 --- a/lib/mysql/parser.js +++ b/lib/mysql/parser.js @@ -2,7 +2,7 @@ if (global.GENTLY) require = GENTLY.hijack(require); // see: http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol -var sys = require('./sys'), +var util = require('util'), Buffer = require('buffer').Buffer, EventEmitter = require('events').EventEmitter, POWS = [1, 256, 65536, 16777216]; @@ -20,7 +20,7 @@ function Parser() { this._lengthCodedLength = null; this._lengthCodedStringLength = null; }; -sys.inherits(Parser, EventEmitter); +util.inherits(Parser, EventEmitter); module.exports = Parser; Parser.prototype.write = function(buffer) { diff --git a/lib/mysql/query.js b/lib/mysql/query.js index 3bcd01e61..c33e0b62d 100644 --- a/lib/mysql/query.js +++ b/lib/mysql/query.js @@ -1,6 +1,6 @@ if (global.GENTLY) require = GENTLY.hijack(require); -var sys = require('./sys'), +var util = require('util'), EventEmitter = require('events').EventEmitter, Parser = require('./parser'), Client; @@ -15,7 +15,7 @@ function Query(properties) { this[key] = properties[key]; } }; -sys.inherits(Query, EventEmitter); +util.inherits(Query, EventEmitter); module.exports = Query; Query.prototype._handlePacket = function(packet) { diff --git a/lib/mysql/sys.js b/lib/mysql/sys.js deleted file mode 100644 index e9493e9ba..000000000 --- a/lib/mysql/sys.js +++ /dev/null @@ -1,6 +0,0 @@ -// Backwards compatibility ... -try { - module.exports = require('util'); -} catch (e) { - module.exports = require('sys'); -} diff --git a/test/common.js b/test/common.js index 85308356b..38490d3bc 100644 --- a/test/common.js +++ b/test/common.js @@ -1,6 +1,6 @@ var path = require('path'); require.paths.unshift(path.dirname(__dirname)+'/lib'); -var sys = require('mysql/sys'); +var util = require('util'); var parent = module.parent.filename; if (parent.match(/test\/system/) || parent.match(/benchmark/)) { @@ -19,7 +19,7 @@ global.TEST_FIXTURES = path.join(__dirname, 'fixture'); global.Gently = require('gently'); global.assert = require('assert'); global.p = function(val) { - sys.error(sys.inspect(val)); + util.error(util.inspect(val)); }; global.GENTLY = new Gently(); From 511ac391fdbfc7d470b185448bb9b94a083d5917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 20 Feb 2011 14:43:15 +0100 Subject: [PATCH 5/8] Get rid of net_constants module This was used to target error constant resolution in multiple node versions. Now that this lib will be v0.4 only, we can safely assume `err.code` to be populated. --- lib/mysql/client.js | 6 +++--- lib/mysql/net_constants.js | 22 --------------------- test/simple/test-client.js | 5 ++--- test/system/test-client-connection-error.js | 7 ++----- 4 files changed, 7 insertions(+), 33 deletions(-) delete mode 100644 lib/mysql/net_constants.js diff --git a/lib/mysql/client.js b/lib/mysql/client.js index f96fe2ab0..f82ca0228 100644 --- a/lib/mysql/client.js +++ b/lib/mysql/client.js @@ -6,8 +6,7 @@ var util = require('util'), Parser = require('./parser'), OutgoingPacket = require('./outgoing_packet'), Query = require('./query'), - EventEmitter = require('events').EventEmitter, - netConstants = require('./net_constants'); + EventEmitter = require('events').EventEmitter; function Client(properties) { if (!(this instanceof Client)) { @@ -50,7 +49,8 @@ Client.prototype.connect = function(cb) { connection .on('error', function(err) { - if (err.errno & (netConstants.ECONNREFUSED | netConstants.ENOTFOUND)) { + var connectionError = err.code && err.code.match(/ECONNREFUSED|ENOTFOUND/); + if (connectionError) { if (cb) { cb(err); return; diff --git a/lib/mysql/net_constants.js b/lib/mysql/net_constants.js deleted file mode 100644 index 1355709ca..000000000 --- a/lib/mysql/net_constants.js +++ /dev/null @@ -1,22 +0,0 @@ -// Constants have been changing through various node versions. -// First we try to look for them in the old location (in the net binding) -// If this fails, we try to get them from the constants module which -// was added in a later version. If that fails we raise an error; - -var NET_CONSTANTS_NOT_FOUND = 'Unable to detect constants location, please report this.'; - -module.exports = process.binding('net'); - -if ('ECONNREFUSED' in module.exports) { - return; -} - -try { - module.exports = require('constants'); -} catch (e) { - throw new Error(NET_CONSTANTS_NOT_FOUND); -} - -if (!('ECONNREFUSED' in module.exports)) { - throw new Error(NET_CONSTANTS_NOT_FOUND); -} diff --git a/test/simple/test-client.js b/test/simple/test-client.js index aac53f682..c9106e7ab 100644 --- a/test/simple/test-client.js +++ b/test/simple/test-client.js @@ -3,8 +3,7 @@ var StreamStub = GENTLY.stub('net', 'Stream'), ParserStub = GENTLY.stub('./parser'), OutgoingPacketStub = GENTLY.stub('./outgoing_packet'), QueryStub = GENTLY.stub('./query'), - Parser = require('mysql/parser'), - netConstants = require('mysql/net_constants'); + Parser = require('mysql/parser'); for (var k in Parser) { ParserStub[k] = Parser[k]; @@ -119,7 +118,7 @@ test(function connect() { (function testConnectionRefusedError() { var ERR = new Error('ouch'); - ERR.errno = netConstants.ECONNREFUSED; + ERR.code = 'ECONNREFUSED'; CB_DELEGATE = gently.expect(function connectCallback(err) { assert.strictEqual(err, ERR); diff --git a/test/system/test-client-connection-error.js b/test/system/test-client-connection-error.js index 0201a876b..5fe20bcf5 100644 --- a/test/system/test-client-connection-error.js +++ b/test/system/test-client-connection-error.js @@ -1,13 +1,10 @@ require('../common'); var Client = require('mysql').Client, client = Client(TEST_CONFIG), - gently = new Gently(), - netConstants = require('mysql/net_constants'); - ECONNREFUSED = netConstants.ECONNREFUSED, - ENOTFOUND = netConstants.ENOTFOUND; + gently = new Gently(); client.host = 'BADHOST'; client.connect(gently.expect(function connectCb(err, result) { - assert.ok(err.errno & (ECONNREFUSED | ENOTFOUND)); + assert.ok(err.code.match(/ECONNREFUSED|ENOTFOUND/)); })); From 1b0e9c88a92e2af67f058dc4a11e20aeb27aabc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 20 Feb 2011 14:56:21 +0100 Subject: [PATCH 6/8] Prepare readme for next release Add changelog, mention new node target version. --- Readme.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index a993a1d33..937d0dde9 100644 --- a/Readme.md +++ b/Readme.md @@ -49,8 +49,10 @@ Or if you don't want to use npm / run the latest source: ## Compatibility -This module should run in any node version >= v0.1.102 (July 26, 2010). -However, using a current version of node is encouraged. +This module is compatible with node v0.4.x. + +If you need to work with an older node version, download v0.9.0. It supports +node >= v0.1.102. ## Design Goals @@ -256,6 +258,29 @@ At this point the module is ready to be tried out, but a lot of things are yet t * Deal with stale connections / other potential network issues * Decide how to handle queries with multiple statements +## Changelog + +### v0.9.1 (not yet released) + +* Fix issue #49 / `client.escape()` throwing exceptions on objects. (Nick Payne) +* Drop < v0.4.x compatibility. From now on you need node v0.4.x to use this module. + +[See Commits](https://github.com/felixge/node-formidable/compare/v0.9.0...v0.9.1) + +### Older releases + +These releases were done before starting to maintain the above Changelog: + +* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0) +* [v0.8.0](https://github.com/felixge/node-formidable/compare/v0.7.0...v0.9.0) +* [v0.7.0](https://github.com/felixge/node-formidable/compare/v0.6.0...v0.9.0) +* [v0.6.0](https://github.com/felixge/node-formidable/compare/v0.5.0...v0.9.0) +* [v0.5.0](https://github.com/felixge/node-formidable/compare/v0.4.0...v0.9.0) +* [v0.4.0](https://github.com/felixge/node-formidable/compare/v0.3.0...v0.9.0) +* [v0.3.0](https://github.com/felixge/node-formidable/compare/v0.2.0...v0.9.0) +* [v0.2.0](https://github.com/felixge/node-formidable/compare/v0.1.0...v0.9.0) +* [v0.1.0](https://github.com/felixge/node-formidable/commits/v0.1.0) + ## License node-mysql is licensed under the MIT license. From 15df342909ced1fe277e71f3b276523886786024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 20 Feb 2011 14:57:26 +0100 Subject: [PATCH 7/8] Update contributors --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index 937d0dde9..fa080a35e 100644 --- a/Readme.md +++ b/Readme.md @@ -18,6 +18,7 @@ very heavy on database interaction your milage may vary. * Brian ([mscdex](http://github.com/felixge/node-mysql/commits/master?author=mscdex)) * Cal Henderson ([iamcal](http://github.com/felixge/node-mysql/commits/master?author=iamcal)) * Frank Grimm ([FrankGrimm](http://github.com/felixge/node-mysql/commits/master?author=FrankGrimm)) +* Nick Payne ([makeusabrew](http://github.com/felixge/node-mysql/commits/master?author=makeusabrew)) ## Sponsors From 1521edacaecd558bce85058e92b3b8dc542f6d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 20 Feb 2011 14:58:51 +0100 Subject: [PATCH 8/8] Bump version --- Readme.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index fa080a35e..9553fe6a1 100644 --- a/Readme.md +++ b/Readme.md @@ -261,7 +261,7 @@ At this point the module is ready to be tried out, but a lot of things are yet t ## Changelog -### v0.9.1 (not yet released) +### v0.9.1 * Fix issue #49 / `client.escape()` throwing exceptions on objects. (Nick Payne) * Drop < v0.4.x compatibility. From now on you need node v0.4.x to use this module. diff --git a/package.json b/package.json index ace6ea2b8..f247824ef 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name" : "mysql" -, "version": "0.9.0" +, "version": "0.9.1" , "devDependencies": {"gently": ">=0.8.0"} , "main" : "./lib/mysql" , "scripts" : { "test" : "make test" }