Skip to content

Commit 913addb

Browse files
committed
Revert "url: support path for url.format"
This reverts commit d312b6d. Reverted for breaking `npm install` with git+ssh URLs. Conflicts: doc/api/url.markdown Fixes: #295 PR-URL: #303 Reviewed-By: Rod Vagg <[email protected]>
1 parent a1e54d6 commit 913addb

File tree

3 files changed

+9
-100
lines changed

3 files changed

+9
-100
lines changed

doc/api/url.markdown

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ Here's how the formatting process works:
9898
* `port` will only be used if `host` is absent.
9999
* `host` will be used in place of `hostname` and `port`
100100
* `pathname` is treated the same with or without the leading `/` (slash).
101-
* `path` is treated the same with `pathname` but able to contain `query` as well.
102101
* `query` (object; see `querystring`) will only be used if `search` is absent.
103102
* `search` will be used in place of `query`.
104103
* It is treated the same with or without the leading `?` (question mark).

lib/url.js

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
364364
}
365365

366366
// finally, reconstruct the href based on what has been validated.
367-
this.href = this.format(parseQueryString);
367+
this.href = this.format();
368368
return this;
369369
};
370370

@@ -379,7 +379,7 @@ function urlFormat(obj) {
379379
return obj.format();
380380
}
381381

382-
Url.prototype.format = function(parseQueryString) {
382+
Url.prototype.format = function() {
383383
var auth = this.auth || '';
384384
if (auth) {
385385
auth = encodeURIComponent(auth);
@@ -391,26 +391,7 @@ Url.prototype.format = function(parseQueryString) {
391391
pathname = this.pathname || '',
392392
hash = this.hash || '',
393393
host = false,
394-
query = '',
395-
search = '';
396-
397-
if (this.path) {
398-
var qm = this.path.indexOf('?');
399-
if (qm !== -1) {
400-
query = this.path.slice(qm + 1);
401-
search = '?' + query;
402-
pathname = this.path.slice(0, qm);
403-
} else {
404-
if (parseQueryString) {
405-
this.query = {};
406-
this.search = '';
407-
} else {
408-
this.query = null;
409-
this.search = null;
410-
}
411-
pathname = this.path;
412-
}
413-
}
394+
query = '';
414395

415396
if (this.host) {
416397
host = auth + this.host;
@@ -423,15 +404,13 @@ Url.prototype.format = function(parseQueryString) {
423404
}
424405
}
425406

426-
if (!query &&
427-
this.query &&
407+
if (this.query &&
428408
util.isObject(this.query) &&
429409
Object.keys(this.query).length) {
430410
query = querystring.stringify(this.query);
431411
}
432412

433-
if (!search)
434-
search = this.search || (query && ('?' + query)) || '';
413+
var search = this.search || (query && ('?' + query)) || '';
435414

436415
if (protocol && protocol.substr(-1) !== ':') protocol += ':';
437416

test/parallel/test-url.js

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ var formatTests = {
11131113

11141114
// `#`,`?` in path
11151115
'/path/to/%%23%3F+=&.txt?foo=theA1#bar' : {
1116-
href: '/path/to/%%23%3F+=&.txt?foo=theA1#bar',
1116+
href : '/path/to/%%23%3F+=&.txt?foo=theA1#bar',
11171117
pathname: '/path/to/%#?+=&.txt',
11181118
query: {
11191119
foo: 'theA1'
@@ -1123,7 +1123,7 @@ var formatTests = {
11231123

11241124
// `#`,`?` in path + `#` in query
11251125
'/path/to/%%23%3F+=&.txt?foo=the%231#bar' : {
1126-
href: '/path/to/%%23%3F+=&.txt?foo=the%231#bar',
1126+
href : '/path/to/%%23%3F+=&.txt?foo=the%231#bar',
11271127
pathname: '/path/to/%#?+=&.txt',
11281128
query: {
11291129
foo: 'the#1'
@@ -1138,7 +1138,7 @@ var formatTests = {
11381138
hostname: 'ex.com',
11391139
hash: '#frag',
11401140
search: '?abc=the#1?&foo=bar',
1141-
pathname: '/foo?100%m#r'
1141+
pathname: '/foo?100%m#r',
11421142
},
11431143

11441144
// `?` and `#` in search only
@@ -1148,77 +1148,8 @@ var formatTests = {
11481148
hostname: 'ex.com',
11491149
hash: '#frag',
11501150
search: '?abc=the#1?&foo=bar',
1151-
pathname: '/fooA100%mBr'
1152-
},
1153-
1154-
// path
1155-
'http://github.com/joyent/node#js1': {
1156-
href: 'http://github.com/joyent/node#js1',
1157-
protocol: 'http:',
1158-
hostname: 'github.com',
1159-
hash: '#js1',
1160-
path: '/joyent/node'
1161-
},
1162-
1163-
// pathname vs. path, path wins
1164-
'http://github.com/joyent/node2#js1': {
1165-
href: 'http://github.com/joyent/node2#js1',
1166-
protocol: 'http:',
1167-
hostname: 'github.com',
1168-
hash: '#js1',
1169-
path: '/joyent/node2',
1170-
pathname: '/joyent/node'
1171-
},
1172-
1173-
// pathname with query/search
1174-
'http://github.com/joyent/node?foo=bar#js2': {
1175-
href: 'http://github.com/joyent/node?foo=bar#js2',
1176-
protocol: 'http:',
1177-
hostname: 'github.com',
1178-
hash: '#js2',
1179-
path: '/joyent/node?foo=bar'
1180-
},
1181-
1182-
// path vs. query, path wins
1183-
'http://github.com/joyent/node?foo=bar2#js3': {
1184-
href: 'http://github.com/joyent/node?foo=bar2#js3',
1185-
protocol: 'http:',
1186-
hostname: 'github.com',
1187-
hash: '#js3',
1188-
path: '/joyent/node?foo=bar2',
1189-
query: {foo: 'bar'}
1190-
},
1191-
1192-
// path vs. search, path wins
1193-
'http://github.com/joyent/node?foo=bar3#js4': {
1194-
href: 'http://github.com/joyent/node?foo=bar3#js4',
1195-
protocol: 'http:',
1196-
hostname: 'github.com',
1197-
hash: '#js4',
1198-
path: '/joyent/node?foo=bar3',
1199-
search: '?foo=bar'
1200-
},
1201-
1202-
// path is present without ? vs. query given
1203-
'http://github.com/joyent/node#js5': {
1204-
href: 'http://github.com/joyent/node#js5',
1205-
protocol: 'http:',
1206-
hostname: 'github.com',
1207-
hash: '#js5',
1208-
path: '/joyent/node',
1209-
query: {foo: 'bar'}
1210-
},
1211-
1212-
// path is present without ? vs. search given
1213-
'http://github.com/joyent/node#js6': {
1214-
href: 'http://github.com/joyent/node#js6',
1215-
protocol: 'http:',
1216-
hostname: 'github.com',
1217-
hash: '#js6',
1218-
path: '/joyent/node',
1219-
search: '?foo=bar'
1151+
pathname: '/fooA100%mBr',
12201152
}
1221-
12221153
};
12231154
for (var u in formatTests) {
12241155
var expect = formatTests[u].href;

0 commit comments

Comments
 (0)