diff --git a/.travis.yml b/.travis.yml index 9097a94..a44cd26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: node_js node_js: - '0.10' - - '0.8' script: make test-coveralls diff --git a/Makefile b/Makefile index 1bcf55a..d419576 100644 --- a/Makefile +++ b/Makefile @@ -28,4 +28,3 @@ test-coveralls: test test-all: test test-cov .PHONY: test - diff --git a/README.md b/README.md index be63634..baf01a8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ cnpmjs.org ======= -[![Build Status](https://secure.travis-ci.org/fengmk2/cnpmjs.org.png)](http://travis-ci.org/fengmk2/cnpmjs.org) [![Coverage Status](https://coveralls.io/repos/fengmk2/cnpmjs.org/badge.png)](https://coveralls.io/r/fengmk2/cnpmjs.org) [![Build Status](https://drone.io/github.com/fengmk2/cnpmjs.org/status.png)](https://drone.io/github.com/fengmk2/cnpmjs.org/latest) +[![Build Status](https://secure.travis-ci.org/fengmk2/cnpmjs.org.png)](http://travis-ci.org/fengmk2/cnpmjs.org) [![Coverage Status](https://coveralls.io/repos/fengmk2/cnpmjs.org/badge.png)](https://coveralls.io/r/fengmk2/cnpmjs.org) [![NPM](https://nodei.co/npm/cnpmjs.org.png?downloads=true&stars=true)](https://nodei.co/npm/cnpmjs.org/) diff --git a/controllers/registry/module.js b/controllers/registry/module.js index 5482da5..49c9507 100644 --- a/controllers/registry/module.js +++ b/controllers/registry/module.js @@ -19,6 +19,7 @@ var debug = require('debug')('cnpmjs.org:controllers:registry:module'); var path = require('path'); var fs = require('fs'); var crypto = require('crypto'); +var eventproxy = require('eventproxy'); var config = require('../../config'); var Module = require('../../proxy/module'); @@ -28,40 +29,43 @@ exports.show = function (req, res, next) { if (err || rows.length === 0) { return next(err); } - var latest; - for (var i = 0; i < rows.length; i++) { - var row = rows[i]; - if (row.version === 'latest') { - latest = row; - break; - } + var nextMod = rows[0]; + var latest = rows[1]; + var startIndex = 1; + if (nextMod.version !== 'next') { + // next create fail + latest = nextMod; + startIndex = 0; + nextMod = null; } + if (!latest) { - return next(); + latest = nextMod; } var distTags = {}; var versions = {}; var times = {}; var attachments = {}; - for (var i = 0; i < rows.length; i++) { + for (var i = startIndex; i < rows.length; i++) { var row = rows[i]; var pkg = row.package; - if (!pkg.version || pkg.version === 'latest') { - continue; - } - versions[pkg.version] = pkg; times[pkg.version] = row.gmt_modified; } - if (latest.package.version || latest.package.version !== 'init') { - distTags['latest'] = latest.package.version; + if (latest.package.version && latest.package.version !== 'next') { + distTags.latest = latest.package.version; + } + + var rev = ''; + if (nextMod) { + rev = String(nextMod.id); } var info = { _id: latest.name, - _rev: String(latest.id), + _rev: rev, name: latest.name, description: latest.package.description, versions: versions, @@ -88,6 +92,9 @@ exports.upload = function (req, res, next) { var name = req.params.name; var id = Number(req.params.rev); var filename = req.params.filename; + var version = filename.substring(filename.indexOf('-') + 1); + version = version.replace(/\.tgz$/, ''); + // save version on pkg upload debug('%s: upload %s, file size: %d', username, req.url, length); Module.getById(id, function (err, mod) { @@ -98,12 +105,20 @@ exports.upload = function (req, res, next) { return item.name === username; }); if (match.length === 0 || mod.name !== name) { - return res.json(401, { - error: 'noperms', + return res.json(403, { + error: 'no_perms', reason: 'Current user can not publish this module' }); } + if (mod.version !== 'next') { + // rev wrong + return res.json(403, { + error: 'rev_wrong', + reason: 'rev not match next module' + }); + } + var filepath = path.join(config.uploadDir, filename); var ws = fs.createWriteStream(filepath); var shasum = crypto.createHash('sha1'); @@ -115,8 +130,8 @@ exports.upload = function (req, res, next) { }); ws.on('finish', function () { if (dataSize !== length) { - return res.json(401, { - error: 'wrongsize', + return res.json(403, { + error: 'size_wrong', reason: 'Header size ' + length + ' not match download size ' + dataSize, }); } @@ -127,12 +142,14 @@ exports.upload = function (req, res, next) { size: length }; mod.package.dist = dist; - debug('%s module: save file to %s, size: %d, sha1: %s, dist: %j', id, filepath, length, shasum, dist); + mod.package.version = version; + debug('%s module: save file to %s, size: %d, sha1: %s, dist: %j, version: %s', + id, filepath, length, shasum, dist, version); Module.update(mod, function (err, result) { if (err) { return next(err); } - res.json(201, {ok: true, rev: String(result.id), date: result.gmt_modified}); + res.json(201, {ok: true, rev: String(result.id)}); }); }); }); @@ -142,14 +159,14 @@ exports.updateLatest = function (req, res, next) { var username = req.session.name; var name = req.params.name; var version = req.params.version; - Module.get(name, 'latest', function (err, mod) { + Module.get(name, 'next', function (err, nextMod) { if (err) { return next(err); } - if (!mod) { + if (!nextMod) { return next(); } - var match = mod.package.maintainers.filter(function (item) { + var match = nextMod.package.maintainers.filter(function (item) { return item.name === username; }); if (match.length === 0) { @@ -159,32 +176,39 @@ exports.updateLatest = function (req, res, next) { }); } - var body = req.body; + // check version if not match pkg upload + if (nextMod.package.version !== version) { + return res.json(403, { + error: 'version_wrong', + reason: 'version not match' + }); + } - mod.version = version; - mod.author = username; - body.dist = mod.package.dist; - body.maintainers = mod.package.maintainers; + var body = req.body; + nextMod.version = version; + nextMod.author = username; + body.dist = nextMod.package.dist; + body.maintainers = nextMod.package.maintainers; if (!body.author) { body.author = { name: username, email: req.session.email, }; } - mod.package = body; - debug('update %s:%s %j', mod.package.name, mod.package.version, mod.package.dist); + nextMod.package = body; + debug('update %s:%s %j', nextMod.package.name, nextMod.package.version, nextMod.package.dist); // change latest to version - Module.update(mod, function (err) { + Module.update(nextMod, function (err) { if (err) { return next(err); } // add a new latest version - mod.version = 'latest'; - Module.add(mod, function (err, result) { + nextMod.version = 'next'; + Module.add(nextMod, function (err, result) { if (err) { return next(err); } - res.json(201, {ok: true, rev: String(result.id), date: result.gmt_modified}); + res.json(201, {ok: true, rev: String(result.id)}); }); }); }); @@ -199,59 +223,65 @@ exports.add = function (req, res, next) { return item.name === username; }); if (match.length === 0) { - return res.json(401, { - error: 'noperms', + return res.json(403, { + error: 'no_perms', reason: 'Current user can not publish this module' }); } - Module.get(name, 'latest', function (err, mod) { - if (err) { - return next(err); + var ep = eventproxy.create(); + ep.fail(next); + + Module.getLatest(name, ep.doneLater('latest')); + Module.get(name, 'next', ep.done(function (nextMod) { + if (nextMod) { + nextMod.exists = true; + return ep.emit('next', nextMod); + } + // ensure next module exits + // because updateLatest will create next module fail + nextMod = { + name: name, + version: 'next', + author: username, + package: { + name: name, + version: 'next', + description: pkg.description, + readme: pkg.readme, + maintainers: pkg.maintainers, + }, + }; + Module.add(nextMod, ep.done(function (result) { + nextMod.id = result.id; + ep.emit('next', nextMod); + })); + })); + + ep.all('latest', 'next', function (latestMod, nextMod) { + var maintainers = latestMod ? latestMod.package.maintainers : nextMod.package.maintainers; + var match = maintainers.filter(function (item) { + return item.name === username; + }); + + if (match.length === 0) { + return res.json(403, { + error: 'no_perms', + reason: 'Current user can not publish this module' + }); } - if (mod) { - match = mod.package.maintainers.filter(function (item) { - return item.name === username; - }); - if (match.length === 0) { - return res.json(401, { - error: 'noperms', - reason: 'Current user can not publish this module' - }); - } - + if (latestMod || nextMod.exists) { return res.json(409, { error: 'conflict', reason: 'Document update conflict.' }); } - mod = { - name: name, - version: 'latest', - author: username, - package: { - name: name, - version: 'init', - description: pkg.description, - readme: pkg.readme, - maintainers: pkg.maintainers, - author: { - name: username, - email: req.session.email, - } - }, - }; - Module.add(mod, function (err, result) { - if (err) { - return next(err); - } - res.json(201, { - ok: true, - id: name, - rev: String(result.id), - }); + res.json(201, { + ok: true, + id: name, + rev: String(nextMod.id), }); }); }; diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..d20debf Binary files /dev/null and b/logo.png differ diff --git a/package.json b/package.json index 966913c..cc926a3 100644 --- a/package.json +++ b/package.json @@ -20,19 +20,19 @@ "debug": "0.7.4", "utility": "0.1.8", "ready": "0.1.1", - "connect": "~2.11.0", - "connect-rt": "~0.0.2", - "connect-redis": "~1.4.6", - "urlrouter": "~0.5.3", - "graceful": "~0.0.5", - "moment": "~2.4.0", - "logfilestream": "~0.1.0", - "ms": "~0.6.1", - "mkdirp": "~0.3.5", + "connect": "2.11.2", + "connect-rt": "0.0.2", + "connect-redis": "1.4.6", + "urlrouter": "0.5.3", + "graceful": "0.0.5", + "moment": "2.4.0", + "logfilestream": "0.1.0", + "ms": "0.6.1", + "mkdirp": "0.3.5", "mysql": "2.0.0-rc1", - "response-patch": "~0.1.1", - "response-cookie": "~0.0.2", - "eventproxy": "~0.2.6" + "response-patch": "0.1.1", + "response-cookie": "0.0.2", + "eventproxy": "0.2.6" }, "devDependencies": { "supertest": "*", diff --git a/proxy/module.js b/proxy/module.js index 5241caa..f5e8e1d 100644 --- a/proxy/module.js +++ b/proxy/module.js @@ -101,7 +101,7 @@ exports.get = function (name, version, callback) { }); }; -var SELECT_LATEST_MODULE_SQL = 'SELECT ' + MODULE_COLUMNS + ' FROM module WHERE name=? ORDER BY id DESC LIMIT 1;'; +var SELECT_LATEST_MODULE_SQL = 'SELECT ' + MODULE_COLUMNS + ' FROM module WHERE name=? AND version <> "next" ORDER BY id DESC LIMIT 1;'; exports.getLatest = function (name, callback) { mysql.queryOne(SELECT_LATEST_MODULE_SQL, [name], function (err, row) { @@ -138,3 +138,9 @@ exports.listByName = function (name, callback) { callback(err, rows); }); }; + +var DELETE_MODULE_BY_NAME_SQL = 'DELETE FROM module WHERE name=?;'; +exports.removeByName = function (name, callback) { + mysql.query(DELETE_MODULE_BY_NAME_SQL, [name], callback); +}; + diff --git a/routes/registry.js b/routes/registry.js index 858debd..20e7894 100644 --- a/routes/registry.js +++ b/routes/registry.js @@ -27,12 +27,13 @@ function routes(app) { // module app.get('/:name', mod.show); + // try to add module app.put('/:name', login, mod.add); // put tarball // https://registry.npmjs.org/cnpmjs.org/-/cnpmjs.org-0.0.0.tgz/-rev/1-c85bc65e8d2470cc4d82b8f40da65b8e app.put('/:name/-/:filename/-rev/:rev', login, mod.upload); - // tag + // put package.json to module app.put('/:name/:version/-tag/latest', login, mod.updateLatest); // try to create a new user diff --git a/servers/registry.js b/servers/registry.js index 647343a..7d136bd 100644 --- a/servers/registry.js +++ b/servers/registry.js @@ -50,6 +50,10 @@ app.use(auth()); app.use(urlrouter(routes)); +app.use(function (req, res, next) { + res.json(404, {error: 'not_found', reason: 'document not found'}); +}); + /** * Error handler */ diff --git a/test/controllers/registry/module.test.js b/test/controllers/registry/module.test.js index 9b94156..63d6cd6 100644 --- a/test/controllers/registry/module.test.js +++ b/test/controllers/registry/module.test.js @@ -14,9 +14,14 @@ * Module dependencies. */ +var fs = require('fs'); +var path = require('path'); var should = require('should'); var request = require('supertest'); var app = require('../../../servers/registry'); +var Module = require('../../../proxy/module'); + +var fixtures = path.join(path.dirname(path.dirname(__dirname)), 'fixtures'); describe('controllers/registry/module.test.js', function () { before(function (done) { @@ -45,4 +50,213 @@ describe('controllers/registry/module.test.js', function () { }); }); }); + + describe('PUT /:name', function () { + var pkg = { + name: 'testputmodule', + description: 'test put module', + readme: 'readme text', + maintainers: [{ + name: 'cnpmjstest10', + email: 'cnpmjstest10@cnpmjs.org' + }], + }; + var baseauth = 'Basic ' + new Buffer('cnpmjstest10:cnpmjstest10').toString('base64'); + var baseauthOther = 'Basic ' + new Buffer('cnpmjstest101:cnpmjstest101').toString('base64'); + var lastRev; + + before(function (done) { + // clean up testputmodule + Module.removeByName('testputmodule', done); + }); + + it('should try to add not exists module return 201', function (done) { + request(app) + .put('/' + pkg.name) + .set('authorization', baseauth) + .send(pkg) + .expect(201, function (err, res) { + should.not.exist(err); + res.body.should.have.keys('ok', 'id', 'rev'); + res.body.ok.should.equal(true); + res.body.id.should.equal(pkg.name); + res.body.rev.should.be.a.String; + done(); + }); + }); + + it('should try to add return 409 when only next module exists', function (done) { + request(app) + .put('/' + pkg.name) + .set('authorization', baseauth) + .send(pkg) + .expect(409, function (err, res) { + should.not.exist(err); + res.body.should.eql({ + error: 'conflict', + reason: 'Document update conflict.' + }); + done(); + }); + }); + + it('should try to add return 403 when not module user and only next module exists', function (done) { + request(app) + .put('/' + pkg.name) + .set('authorization', baseauthOther) + .send(pkg) + .expect(403, function (err, res) { + should.not.exist(err); + res.body.should.eql({ + error: 'no_perms', + reason: 'Current user can not publish this module' + }); + done(); + }); + }); + + it('should get versions empty when only next module exists', function (done) { + request(app) + .get('/' + pkg.name) + .expect(200, function (err, res) { + should.not.exist(err); + res.body.should.have.keys('_id', '_rev', 'name', 'description', 'versions', 'dist-tags', + 'readme', 'maintainers', 'time', '_attachments'); + res.body.versions.should.eql({}); + res.body.time.should.eql({}); + res.body['dist-tags'].should.eql({}); + lastRev = res.body._rev; + console.log('lastRev: %s', lastRev); + done(); + }); + }); + + it('should upload tarball success: /:name/-/:filename/-rev/:rev', function (done) { + var body = fs.readFileSync(path.join(fixtures, 'testputmodule-0.1.9.tgz')); + request(app) + .put('/' + pkg.name + '/-/' + pkg.name + '-0.1.9.tgz/-rev/' + lastRev) + .set('authorization', baseauth) + .set('content-type', 'application/octet-stream') + .set('content-length', '' + body.length) + .send(body) + .expect(201, function (err, res) { + should.not.exist(err); + res.body.should.eql({ + ok: true, + rev: lastRev, + }); + done(); + }); + }); + + it('should upload tarball success again: /:name/-/:filename/-rev/:rev', function (done) { + var body = fs.readFileSync(path.join(fixtures, 'testputmodule-0.1.9.tgz')); + request(app) + .put('/' + pkg.name + '/-/' + pkg.name + '-0.1.9.tgz/-rev/' + lastRev) + .set('authorization', baseauth) + .set('content-type', 'application/octet-stream') + .set('content-length', '' + body.length) + .send(body) + .expect(201, function (err, res) { + should.not.exist(err); + res.body.should.eql({ + ok: true, + rev: lastRev, + }); + done(); + }); + }); + + // it('should upload tarball fail 403 when header size not match body size', function (done) { + // var body = fs.readFileSync(path.join(fixtures, 'testputmodule-0.1.9.tgz')); + // request(app) + // .put('/' + pkg.name + '/-/' + pkg.name + '-0.1.9.tgz/-rev/' + lastRev) + // .set('authorization', baseauth) + // .set('content-type', 'application/octet-stream') + // .set('content-length', '' + (body.length + 1)) + // .send(body) + // .expect(404, function (err, res) { + // should.not.exist(err); + // res.body.should.eql({ + // error: 'size_wrong', + // reason: 'document not found' + // }); + // done(); + // }); + // }); + + it('should upload tarball fail 403 when rev not match current module', function (done) { + var body = fs.readFileSync(path.join(fixtures, 'testputmodule-0.1.9.tgz')); + request(app) + .put('/' + pkg.name + '/-/' + pkg.name + '-0.1.9.tgz/-rev/25') + .set('authorization', baseauth) + .set('content-type', 'application/octet-stream') + .set('content-length', '' + body.length) + .send(body) + .expect(403, function (err, res) { + should.not.exist(err); + res.body.should.eql({ + error: 'no_perms', + reason: 'Current user can not publish this module' + }); + done(); + }); + }); + + it('should upload tarball fail 404 when rev wrong', function (done) { + var body = fs.readFileSync(path.join(fixtures, 'testputmodule-0.1.9.tgz')); + request(app) + .put('/' + pkg.name + '/-/' + pkg.name + '-0.1.9.tgz/-rev/' + lastRev + '1') + .set('authorization', baseauth) + .set('content-type', 'application/octet-stream') + .set('content-length', '' + body.length) + .send(body) + .expect(404, function (err, res) { + should.not.exist(err); + res.body.should.eql({ + error: 'not_found', + reason: 'document not found' + }); + done(); + }); + }); + + it('should update package.json info success: /:name/:version/-tag/latest', function (done) { + var pkg = require(path.join(fixtures, 'testputmodule.json')).versions['0.1.8']; + pkg.name = 'testputmodule'; + pkg.version = '0.1.9'; + request(app) + .put('/' + pkg.name + '/' + pkg.version + '/-tag/latest') + .set('authorization', baseauth) + .send(pkg) + .expect(201, function (err, res) { + should.not.exist(err); + res.body.should.eql({ + ok: true, + rev: Number(lastRev) + 1 + }); + done(); + }); + }); + + it('should update package.json info again fail 403: /:name/:version/-tag/latest', function (done) { + var pkg = require(path.join(fixtures, 'testputmodule.json')).versions['0.1.8']; + pkg.name = 'testputmodule'; + pkg.version = '0.1.10'; + request(app) + .put('/' + pkg.name + '/' + pkg.version + '/-tag/latest') + .set('authorization', baseauth) + .send(pkg) + .expect(403, function (err, res) { + should.not.exist(err); + res.body.should.eql({ + error: 'version_wrong', + reason: 'version not match' + }); + done(); + }); + }); + + + }); }); diff --git a/test/fixtures/testputmodule-0.1.9.tgz b/test/fixtures/testputmodule-0.1.9.tgz new file mode 100644 index 0000000..81dcebf Binary files /dev/null and b/test/fixtures/testputmodule-0.1.9.tgz differ diff --git a/test/fixtures/testputmodule.json b/test/fixtures/testputmodule.json new file mode 100644 index 0000000..5105d9c --- /dev/null +++ b/test/fixtures/testputmodule.json @@ -0,0 +1 @@ +{"_id":"utility","_rev":"45-26b0aa6f80ab9465e551ed9c0a244aa1","name":"utility","description":"A collection of useful utilities.","dist-tags":{"latest":"0.1.8"},"versions":{"0.0.1":{"name":"utility","version":"0.0.1","description":"A collection of useful utilities.","main":"index.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{"should":"*","jscover":"*","mocha":"*"},"repository":{"type":"git","url":"git://github.com/fengmk2/utility.git"},"keywords":["utility"],"author":{"name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","readme":"utility [![Build Status](https://secure.travis-ci.org/fengmk2/utility.png)](http://travis-ci.org/fengmk2/utility)\n=======\n\n![logo](https://raw.github.com/fengmk2/utility/master/logo.png)\n\nDescription\n\n* jscoverage: [100%](http://fengmk2.github.com/coverage/utility.html)\n\n## Install\n\n```bash\n$ npm install utility\n```\n\n## Usage\n\n```js\nvar utils = require('utility');\n\n// md5 hash\nutils.md5('aer'); // 'd194f6194fc458544482bbb8f0b74c6b'\nutils.md5(new Buffer('')); // 'd41d8cd98f00b204e9800998ecf8427e'\n\n// empty function\nprocess.nextTick(utils.noop);\nfunction foo(callback) {\n callback = callback || utils.noop;\n}\n```\n\n## License \n\n(The MIT License)\n\nCopyright (c) 2012 fengmk2 <fengmk2@gmail.com>\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","readmeFilename":"README.md","_id":"utility@0.0.1","dist":{"shasum":"cdaa6bd91c808af13fde8645a166e21cdce0c55a","tarball":"http://registry.npmjs.org/utility/-/utility-0.0.1.tgz"},"_npmVersion":"1.1.65","_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"}],"directories":{}},"0.0.2":{"name":"utility","version":"0.0.2","description":"A collection of useful utilities.","main":"index.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{"should":"*","jscover":"*","mocha":"*"},"repository":{"type":"git","url":"git://github.com/fengmk2/utility.git"},"keywords":["utility"],"author":{"name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","readme":"utility [![Build Status](https://secure.travis-ci.org/fengmk2/utility.png)](http://travis-ci.org/fengmk2/utility)\n=======\n\n![logo](https://raw.github.com/fengmk2/utility/master/logo.png)\n\nDescription\n\n* jscoverage: [100%](http://fengmk2.github.com/coverage/utility.html)\n\n## Install\n\n```bash\n$ npm install utility\n```\n\n## Usage\n\n```js\nvar utils = require('utility');\n\n// md5 hash\nutils.md5('aer'); // 'd194f6194fc458544482bbb8f0b74c6b'\nutils.md5(new Buffer('')); // 'd41d8cd98f00b204e9800998ecf8427e'\n\n// base64 encode\nutils.base64encode('ä½ å¥½ï¿¥'); // '5L2g5aW977+l'\nutils.base64decode('5L2g5aW977+l') // 'ä½ å¥½ï¿¥'\n\n// urlsafe base64 encode\nutils.base64encode('ä½ å¥½ï¿¥', true); // '5L2g5aW977-l'\nutils.base64decode('5L2g5aW977-l', true); // 'ä½ å¥½ï¿¥'\n\n// empty function\nprocess.nextTick(utils.noop);\nfunction foo(callback) {\n callback = callback || utils.noop;\n}\n\n// html escape\nutils.escape('