Skip to content

Commit

Permalink
fix allow port number in job url. closes #68
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsbalodis committed Nov 6, 2014
1 parent 8723aab commit 9f9e919
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
32 changes: 21 additions & 11 deletions extension/scripts/Job.js
Expand Up @@ -16,31 +16,41 @@ Job.prototype = {

combineUrls: function (parentUrl, childUrl) {

var urlMatcher = new RegExp("(https?://)?([a-z0-9\\-\\.]+\\.[a-z0-9\\-]+|\\d{1,3}\.\\d{1,3}\.\\d{1,3}\.\\d{1,3})?(\\/[^\\?]*\\/|\\/)?([^\\?]*)?(\\?.*)?", "i");
var urlMatcher = new RegExp("(https?://)?([a-z0-9\\-\\.]+\\.[a-z0-9\\-]+(:\\d+)?|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}(:\\d+)?)?(\\/[^\\?]*\\/|\\/)?([^\\?]*)?(\\?.*)?", "i");

var parentMatches = parentUrl.match(urlMatcher);
var childMatches = childUrl.match(urlMatcher);

// special case for urls like this: ?a=1 or like-this/
if (childMatches[1] === undefined && childMatches[2] === undefined && childMatches[3] === undefined && childMatches[4] === undefined) {
if (childMatches[1] === undefined && childMatches[2] === undefined && childMatches[5] === undefined && childMatches[6] === undefined) {

var url = parentMatches[1] + parentMatches[2] + parentMatches[3] + parentMatches[4] + childMatches[5];
var url = parentMatches[1] + parentMatches[2] + parentMatches[5] + parentMatches[6] + childMatches[7];
return url;
}

for (var i = 1; i <= 3; i++) {
if (childMatches[i] === undefined) {
childMatches[i] = parentMatches[i];
}
if (childMatches[1] === undefined) {
childMatches[1] = parentMatches[1];
}
if (childMatches[4] === undefined) {
childMatches[4] = "";
if (childMatches[2] === undefined) {
childMatches[2] = parentMatches[2];
}
if (childMatches[5] === undefined) {
childMatches[5] = "";
if(parentMatches[5] === undefined) {
childMatches[5] = '/';
}
else {
childMatches[5] = parentMatches[5];
}
}

if (childMatches[6] === undefined) {
childMatches[6] = "";
}
if (childMatches[7] === undefined) {
childMatches[7] = "";
}

return childMatches[1] + childMatches[2] + childMatches[3] + childMatches[4] + childMatches[5];
return childMatches[1] + childMatches[2] + childMatches[5] + childMatches[6] + childMatches[7];
},

execute: function (browser, callback, scope) {
Expand Down
15 changes: 15 additions & 0 deletions tests/spec/JobSpec.js
Expand Up @@ -10,6 +10,10 @@ describe("Job", function () {
var child = new Job("/test/", null, null, parent);
expect(child.url).toBe("http://example.com/test/");

var parent = new Job("http://example.com");
var child = new Job("test/", null, null, parent);
expect(child.url).toBe("http://example.com/test/");

var parent = new Job("http://example.com/asdasdad");
var child = new Job("tvnet.lv", null, null, parent);
expect(child.url).toBe("http://tvnet.lv/");
Expand Down Expand Up @@ -39,6 +43,17 @@ describe("Job", function () {
expect(child.url).toBe("http://www.sportstoto.com.my/popup_past_results.asp?drawNo=418/92");
});

it("should be able to create correct url with a port number", function () {

var parent = new Job("http://nukrobi2.nuk.uni-lj.si:8080/wayback/20101021090940/http://volitve.gov.si/lv2010/kandidati/seznam_obcin.html");
var child = new Job("http://nukrobi2.nuk.uni-lj.si:8080/wayback/20101021091250/http://volitve.gov.si/lv2010/kandidati/zupani_os_celje.html", null, null, parent);
expect(child.url).toBe("http://nukrobi2.nuk.uni-lj.si:8080/wayback/20101021091250/http://volitve.gov.si/lv2010/kandidati/zupani_os_celje.html");

var parent = new Job("http://nukrobi2.nuk.uni-lj.si:8080");
var child = new Job("zupani_os_celje.html", null, null, parent);
expect(child.url).toBe("http://nukrobi2.nuk.uni-lj.si:8080/zupani_os_celje.html");
});

it("should not override data with base data if it already exists", function() {

var browser = {
Expand Down

0 comments on commit 9f9e919

Please sign in to comment.