This commit is contained in:
Atul Varma 2015-01-29 11:37:08 -05:00
Родитель 13b276d6ea
Коммит fd6118bb7d
2 изменённых файлов: 31 добавлений и 8 удалений

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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() {