Skip to content

Commit

Permalink
[changed] Combine URL helpers into URL module
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Jul 17, 2014
1 parent 8c43c82 commit 6c74c69
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
9 changes: 4 additions & 5 deletions modules/helpers/Path.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var invariant = require('react/lib/invariant');
var merge = require('react/lib/merge');
var qs = require('querystring');
var urlDecode = require('./urlDecode');
var urlEncode = require('./urlEncode');
var URL = require('./URL');

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

return null;
}

var compiled = compilePattern(pattern);
var match = urlDecode(path).match(compiled.matcher);
var match = URL.decode(path).match(compiled.matcher);

if (!match)
return null;
Expand Down Expand Up @@ -89,7 +88,7 @@ var Path = {
'Missing "' + paramName + '" parameter for path "' + pattern + '"'
);

return urlEncode(params[paramName]);
return URL.encode(params[paramName]);
});
},

Expand Down
22 changes: 22 additions & 0 deletions modules/helpers/URL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var urlEncodedSpaceRE = /\+/g;
var encodedSpaceRE = /%20/g;

var URL = {

/* These functions were copied from the https://github.com/cujojs/rest source, MIT licensed */

decode: function (str) {
// spec says space should be encoded as '+'
str = str.replace(urlEncodedSpaceRE, ' ');
return decodeURIComponent(str);
},

encode: function (str) {
str = encodeURIComponent(str);
// spec says space should be encoded as '+'
return str.replace(encodedSpaceRE, '+');
}

};

module.exports = URL;
11 changes: 0 additions & 11 deletions modules/helpers/urlDecode.js

This file was deleted.

11 changes: 0 additions & 11 deletions modules/helpers/urlEncode.js

This file was deleted.

0 comments on commit 6c74c69

Please sign in to comment.