Skip to content

Commit 6c74c69

Browse files
committed
[changed] Combine URL helpers into URL module
1 parent 8c43c82 commit 6c74c69

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

modules/helpers/Path.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
var invariant = require('react/lib/invariant');
22
var merge = require('react/lib/merge');
33
var qs = require('querystring');
4-
var urlDecode = require('./urlDecode');
5-
var urlEncode = require('./urlEncode');
4+
var URL = require('./URL');
65

76
var paramMatcher = /((?::[a-z_$][a-z0-9_$]*)|\*)/ig;
87
var queryMatcher = /\?(.+)/;
@@ -43,14 +42,14 @@ var Path = {
4342
*/
4443
extractParams: function (pattern, path) {
4544
if (!isDynamicPattern(pattern)) {
46-
if (pattern === urlDecode(path))
45+
if (pattern === URL.decode(path))
4746
return {}; // No dynamic segments, but the paths match.
4847

4948
return null;
5049
}
5150

5251
var compiled = compilePattern(pattern);
53-
var match = urlDecode(path).match(compiled.matcher);
52+
var match = URL.decode(path).match(compiled.matcher);
5453

5554
if (!match)
5655
return null;
@@ -89,7 +88,7 @@ var Path = {
8988
'Missing "' + paramName + '" parameter for path "' + pattern + '"'
9089
);
9190

92-
return urlEncode(params[paramName]);
91+
return URL.encode(params[paramName]);
9392
});
9493
},
9594

modules/helpers/URL.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var urlEncodedSpaceRE = /\+/g;
2+
var encodedSpaceRE = /%20/g;
3+
4+
var URL = {
5+
6+
/* These functions were copied from the https://github.com/cujojs/rest source, MIT licensed */
7+
8+
decode: function (str) {
9+
// spec says space should be encoded as '+'
10+
str = str.replace(urlEncodedSpaceRE, ' ');
11+
return decodeURIComponent(str);
12+
},
13+
14+
encode: function (str) {
15+
str = encodeURIComponent(str);
16+
// spec says space should be encoded as '+'
17+
return str.replace(encodedSpaceRE, '+');
18+
}
19+
20+
};
21+
22+
module.exports = URL;

modules/helpers/urlDecode.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

modules/helpers/urlEncode.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)