From 5035345d47512f83cfd8869fb604d11ff2411c7f Mon Sep 17 00:00:00 2001 From: Aurelio De Rosa Date: Sun, 22 Nov 2015 20:12:51 +0000 Subject: [PATCH] Better extraction of next URL --- github.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/github.js b/github.js index 05f44259..106e5f0f 100644 --- a/github.js +++ b/github.js @@ -122,16 +122,15 @@ results.push.apply(results, res); - var links = (xhr.getResponseHeader('link') || '').split(/\s*,\s*/g); - var next = null; - - links.forEach(function(link) { - next = /rel="next"/.test(link) ? link : next; - }); - - if (next) { - next = (/<(.*)>/.exec(next) || [])[1]; - } + var next = (xhr.getResponseHeader('link') || '') + .split(';') + .filter(function(part) { + return part.search(/rel="next"/) !== -1; + }) + .map(function(part) { + return part.match(/<(.+?)>/)[1]; + }) + .pop(); if (!next) { cb(err, results);