Permalink
Browse files

out file path bug fix for http:/foo/bar.jpg

  • Loading branch information...
1 parent 219a79e commit 98264cda678117c5040f8b5cde3a79720d2e1641 @saml committed Aug 5, 2013
Showing with 63 additions and 9 deletions.
  1. +2 −2 src/UrlParser.js
  2. +61 −7 test/UrlParserTest.js
View
@@ -11,7 +11,7 @@ var Module = function(srcDir, destDir) {
var PathUrlRE = /^\/*(https?)(?:\:\/)?\/(.+)$/;
- var PathRE = /^\/*([^:]+)$/;
+ var PathRE = /^\/*(.+)$/;
var HttpUrlRE = /^(https?)(?:\:\/)?\/(.+)$/;
var normalizeUrl = function(url) {
@@ -30,7 +30,7 @@ var Module = function(srcDir, destDir) {
};
var getOutputPath = function(url) {
- return path.join(destDir, url);
+ return path.join(destDir, normalizeUrl(url));
};
var getRemoteOriginUrl = function(imgId) {
View
@@ -4,18 +4,72 @@ var UrlParser = require('../src/UrlParser');
describe('UrlParser', function() {
describe('#parse()', function() {
- var urlParser = UrlParser('/imgdir', '/thumbnaildir');
+ var urlParser = UrlParser('/src', '/out');
- it('should parse remoteUrl', function() {
- assert.equal('http://imgur.com/a.jpg', urlParser.parse('/http://imgur.com/a.100x200.jpg').remoteUrl);
+ var centerCropRemote = urlParser.parse('/http://imgur.com/a.100x200.jpg');
+
+ it('center crop remote -> remoteUrl', function() {
+ assert.equal('http://imgur.com/a.jpg', centerCropRemote.remoteUrl);
+ });
+
+ it('center crop remote -> out', function() {
+ assert.equal('/out/http/imgur.com/a.100x200.jpg', centerCropRemote.out);
+ });
+
+ it('center crop remote -> src', function() {
+ assert.equal('/src/http/imgur.com/a.jpg', centerCropRemote.src);
+ });
+
+ var centerCropRemoteNormalized = urlParser.parse('/http/imgur.com/a.100x200.jpg');
+
+ it('center crop remote normalized -> remoteUrl', function() {
+ assert.equal('http://imgur.com/a.jpg', centerCropRemoteNormalized.remoteUrl);
+ });
+
+ it('center crop remote normalized -> out', function() {
+ assert.equal('/out/http/imgur.com/a.100x200.jpg', centerCropRemoteNormalized.out);
+ });
+
+ it('center crop remote normalized -> src', function() {
+ assert.equal('/src/http/imgur.com/a.jpg', centerCropRemoteNormalized.src);
+ });
+
+ var badProtocol = urlParser.parse('/httpa/imgur.com/a.100x200sw.jpg');
+ it('httpa -> remoteUrl', function() {
+ assert.equal(null, badProtocol.remoteUrl);
+ });
+
+ it('httpa -> src', function() {
+ assert.equal('/src/httpa/imgur.com/a.jpg', badProtocol.src);
+ });
+
+
+ it('httpa -> out', function() {
+ assert.equal('/out/httpa/imgur.com/a.100x200sw.jpg', badProtocol.out);
+ });
+
+ it('a', function() {
+ assert.equal(null, urlParser.parse('/http:/imgur.com/a.100x200t.jpg').remoteUrl);
+ });
+
+ it('b', function() {
+ assert.equal('http://imgur.com/a.jpg', urlParser.parse('/http/imgur.com/a.100x200sw.jpg').remoteUrl);
+ });
+
+ it('c', function() {
+ assert.equal('https://imgur.com/a.jpg', urlParser.parse('/https/imgur.com/a.100x200sw.jpg').remoteUrl);
+ });
+
+ it('d', function() {
+ assert.equal('https://imgur.com/a.100x200abc.jpg', urlParser.parse('/https/imgur.com/a.100x200abc.jpg').remoteUrl);
});
- it('should parse remoteUrl without ://', function() {
- assert.equal('http://imgur.com/a.jpg', urlParser.parse('/http/imgur.com/a.100x200.jpg').remoteUrl);
+ it('e', function() {
+ assert.equal('https://imgur.com/a.jpg', urlParser.parse('/https://imgur.com/a.100x200sw.jpg').remoteUrl);
});
- it('should reject false remoteUrl', function() {
- assert.equal(null, urlParser.parse('/httpa/imgur.com/a.100x200.jpg').remoteUrl);
+ it('dirname a', function() {
+ assert.equal('https://imgur.com/a.jpg', urlParser.parse('/https://imgur.com/a.100x200sw.jpg').remoteUrl);
});
});
});

0 comments on commit 98264cd

Please sign in to comment.