Skip to content

Commit 9f9e919

Browse files
fix allow port number in job url. closes #68
1 parent 8723aab commit 9f9e919

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

extension/scripts/Job.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,41 @@ Job.prototype = {
1616

1717
combineUrls: function (parentUrl, childUrl) {
1818

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

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

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

27-
var url = parentMatches[1] + parentMatches[2] + parentMatches[3] + parentMatches[4] + childMatches[5];
27+
var url = parentMatches[1] + parentMatches[2] + parentMatches[5] + parentMatches[6] + childMatches[7];
2828
return url;
2929
}
3030

31-
for (var i = 1; i <= 3; i++) {
32-
if (childMatches[i] === undefined) {
33-
childMatches[i] = parentMatches[i];
34-
}
31+
if (childMatches[1] === undefined) {
32+
childMatches[1] = parentMatches[1];
3533
}
36-
if (childMatches[4] === undefined) {
37-
childMatches[4] = "";
34+
if (childMatches[2] === undefined) {
35+
childMatches[2] = parentMatches[2];
3836
}
3937
if (childMatches[5] === undefined) {
40-
childMatches[5] = "";
38+
if(parentMatches[5] === undefined) {
39+
childMatches[5] = '/';
40+
}
41+
else {
42+
childMatches[5] = parentMatches[5];
43+
}
44+
}
45+
46+
if (childMatches[6] === undefined) {
47+
childMatches[6] = "";
48+
}
49+
if (childMatches[7] === undefined) {
50+
childMatches[7] = "";
4151
}
4252

43-
return childMatches[1] + childMatches[2] + childMatches[3] + childMatches[4] + childMatches[5];
53+
return childMatches[1] + childMatches[2] + childMatches[5] + childMatches[6] + childMatches[7];
4454
},
4555

4656
execute: function (browser, callback, scope) {

tests/spec/JobSpec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ describe("Job", function () {
1010
var child = new Job("/test/", null, null, parent);
1111
expect(child.url).toBe("http://example.com/test/");
1212

13+
var parent = new Job("http://example.com");
14+
var child = new Job("test/", null, null, parent);
15+
expect(child.url).toBe("http://example.com/test/");
16+
1317
var parent = new Job("http://example.com/asdasdad");
1418
var child = new Job("tvnet.lv", null, null, parent);
1519
expect(child.url).toBe("http://tvnet.lv/");
@@ -39,6 +43,17 @@ describe("Job", function () {
3943
expect(child.url).toBe("http://www.sportstoto.com.my/popup_past_results.asp?drawNo=418/92");
4044
});
4145

46+
it("should be able to create correct url with a port number", function () {
47+
48+
var parent = new Job("http://nukrobi2.nuk.uni-lj.si:8080/wayback/20101021090940/http://volitve.gov.si/lv2010/kandidati/seznam_obcin.html");
49+
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);
50+
expect(child.url).toBe("http://nukrobi2.nuk.uni-lj.si:8080/wayback/20101021091250/http://volitve.gov.si/lv2010/kandidati/zupani_os_celje.html");
51+
52+
var parent = new Job("http://nukrobi2.nuk.uni-lj.si:8080");
53+
var child = new Job("zupani_os_celje.html", null, null, parent);
54+
expect(child.url).toBe("http://nukrobi2.nuk.uni-lj.si:8080/zupani_os_celje.html");
55+
});
56+
4257
it("should not override data with base data if it already exists", function() {
4358

4459
var browser = {

0 commit comments

Comments
 (0)