From fd6118bb7d8942c041ec94b43452946ead23def9 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Thu, 29 Jan 2015 11:37:08 -0500 Subject: [PATCH] accept goggles makes. fixes #11. --- makes.js | 23 +++++++++++++++-------- test/makes.test.js | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/makes.js b/makes.js index 5d62580..870505e 100644 --- a/makes.js +++ b/makes.js @@ -1,7 +1,8 @@ var request = require('request'); var urlParse = require('url').parse; -var MAKES_URL_RE = /^https:\/\/[A-Za-z0-9_\-]+\.makes\.org\//; +var HTTPS_MAKES_URL_RE = /^https:\/\/[A-Za-z0-9_\-]+\.makes\.org\//; +var GOGGLES_URL_RE = /^http:\/\/[A-Za-z0-9_\-]+\.makes\.org\/goggles\//; var ENDS_WITH_UNDERSCORE_RE = /_$/; function hostnameAndPath(url) { @@ -10,16 +11,22 @@ function hostnameAndPath(url) { } function fromUrl(url) { - if (!MAKES_URL_RE.test(url)) return null; + var contentUrl = null; - var contentUrl = url; + if (HTTPS_MAKES_URL_RE.test(url)) { + contentUrl = url; - if (ENDS_WITH_UNDERSCORE_RE.test(url)) { - url = url.slice(0, -1); - } else { - contentUrl += '_'; + if (ENDS_WITH_UNDERSCORE_RE.test(url)) { + url = url.slice(0, -1); + } else { + contentUrl += '_'; + } + } else if (GOGGLES_URL_RE.test(url)) { + contentUrl = url; } + if (!contentUrl) return null; + return { url: url, contentUrl: contentUrl, @@ -28,7 +35,7 @@ function fromUrl(url) { } function fromHostnameAndPath(str) { - return fromUrl('https://' + str); + return fromUrl('http://' + str) || fromUrl('https://' + str); } function validateAndNormalizeUrl(url) { diff --git a/test/makes.test.js b/test/makes.test.js index 520ccbe..6e2521e 100644 --- a/test/makes.test.js +++ b/test/makes.test.js @@ -18,6 +18,14 @@ describe("makes", function() { url: 'https://foo.makes.org/blah' }); }); + + it("should work for goggles makes", function() { + from('foo.makes.org/goggles/blah').should.eql({ + contentUrl: 'http://foo.makes.org/goggles/blah', + hostnameAndPath: 'foo.makes.org/goggles/blah', + url: 'http://foo.makes.org/goggles/blah' + }); + }); }); describe("fromUrl()", function() { @@ -44,6 +52,14 @@ describe("makes", function() { hostnameAndPath: 'foo.makes.org/' }); }); + + it("should accept goggles makes", function() { + fromUrl('http://foo.makes.org/goggles/blah').should.eql({ + contentUrl: 'http://foo.makes.org/goggles/blah', + hostnameAndPath: 'foo.makes.org/goggles/blah', + url: 'http://foo.makes.org/goggles/blah' + }); + }); }); describe("validateAndNormalizeUrl()", function() {