Skip to content

Commit

Permalink
Fix first slash problem
Browse files Browse the repository at this point in the history
  • Loading branch information
pvorb committed Mar 5, 2012
1 parent 606f7f3 commit 651cc51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions comments.js
@@ -1,6 +1,7 @@
var append = require('append'); var append = require('append');
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var url = require('url');
var sha1 = require('sha1'); var sha1 = require('sha1');
var md5 = require('MD5'); var md5 = require('MD5');
var querystring = require('querystring'); var querystring = require('querystring');
Expand Down Expand Up @@ -308,15 +309,16 @@ Comments.prototype.sendPingbacks = function sendPingbacks(res, pinged) {
return pinged(err); return pinged(err);


if (num != 0) if (num != 0)
return pinged(new Error('Already sent pingbacks for '+res+'.')); return pinged(new Error('Already sent pingbacks for "'+res+'".'));


// if not, send pingbacks // if not, send pingbacks
fs.readFile(path.resolve(self.opt.publicDirectory, res), 'utf8', fs.readFile(path.resolve(self.opt.publicDirectory, './'+res), 'utf8',
function (err, html) { function (err, html) {
if (err) if (err)
return pinged(err); return pinged(err);


Pingback.scan(html, self.opt.urlPrefix+res, function (err, pb) { Pingback.scan(html, url.resolve(self.opt.urlPrefix, res),
function (err, pb) {
if (err) { if (err) {
return col.pingbacks.update({ _id: res }, { return col.pingbacks.update({ _id: res }, {
$set: { sent: true } $set: { sent: true }
Expand Down Expand Up @@ -349,12 +351,8 @@ Comments.prototype.handlePingback


var ping = new Pingback(req, resp); var ping = new Pingback(req, resp);
ping.on('ping', function (source, target, next) { ping.on('ping', function (source, target, next) {
// if target.pathname starts with slash, remove it
if (target.pathname[0] == '/')
target.pathname = target.pathname.substr(1);

// check if it’s a file // check if it’s a file
fs.stat(path.resolve(self.opt.publicDirectory, target.pathname), fs.stat(path.resolve(self.opt.publicDirectory, '.'+target.pathname),
function (err, stats) { function (err, stats) {
if (err) if (err)
return next(Pingback.TARGET_DOES_NOT_EXIST); return next(Pingback.TARGET_DOES_NOT_EXIST);
Expand Down
4 changes: 2 additions & 2 deletions test/pingback.js
Expand Up @@ -40,11 +40,11 @@ source.listen(1337, function () {
target.listen(1338, function () { target.listen(1338, function () {


// test // test
c1.sendPingbacks('hello.html', function () { c1.sendPingbacks('/hello.html', function () {
console.log('Sent pingbacks'); console.log('Sent pingbacks');
}); });


c2.sendPingbacks('world.html', function () { c2.sendPingbacks('/world.html', function () {
console.log('Sent pingbacks'); console.log('Sent pingbacks');
}); });


Expand Down

0 comments on commit 651cc51

Please sign in to comment.