File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -2,14 +2,6 @@ var invariant = require('react/lib/invariant');
2
2
var merge = require ( 'qs/lib/utils' ) . merge ;
3
3
var qs = require ( 'qs' ) ;
4
4
5
- function decodePathSegment ( string ) {
6
- return decodeURIComponent ( string . replace ( / \+ / g, ' ' ) ) ;
7
- }
8
-
9
- function encodePathSegment ( string ) {
10
- return encodeURIComponent ( string ) . replace ( / % 2 0 / g, '+' ) ;
11
- }
12
-
13
5
var paramCompileMatcher = / : ( [ a - z A - Z _ $ ] [ a - z A - Z 0 - 9 _ $ ] * ) | [ * . ( ) \[ \] \\ + | { } ^ $ ] / g;
14
6
var paramInjectMatcher = / : ( [ a - z A - Z _ $ ] [ a - z A - Z 0 - 9 _ $ ? ] * [ ? ] ? ) | [ * ] / g;
15
7
var paramInjectTrailingSlashMatcher = / \/ \/ \? | \/ \? / g;
@@ -46,15 +38,15 @@ var Path = {
46
38
/**
47
39
* Safely decodes special characters in the given URL path.
48
40
*/
49
- decode : function decodePath ( path ) {
50
- return String ( path ) . split ( '/' ) . map ( decodePathSegment ) . join ( '/' ) ;
41
+ decode : function ( path ) {
42
+ return decodeURI ( path . replace ( / \+ / g , ' ' ) ) ;
51
43
} ,
52
44
53
45
/**
54
46
* Safely encodes special characters in the given URL path.
55
47
*/
56
- encode : function encodePath ( path ) {
57
- return String ( path ) . split ( '/' ) . map ( encodePathSegment ) . join ( '/ ') ;
48
+ encode : function ( path ) {
49
+ return encodeURI ( path ) . replace ( / % 2 0 / g , '+ ') ;
58
50
} ,
59
51
60
52
/**
Original file line number Diff line number Diff line change 1
1
var expect = require ( 'expect' ) ;
2
2
var Path = require ( '../Path' ) ;
3
3
4
+ describe ( 'Path.decode' , function ( ) {
5
+ it ( 'properly decodes a path with a query string' , function ( ) {
6
+ expect ( Path . decode ( '/my/short+path?a=b&c=d' ) ) . toEqual ( '/my/short path?a=b&c=d' ) ;
7
+ } ) ;
8
+ } ) ;
9
+
10
+ describe ( 'Path.encode' , function ( ) {
11
+ it ( 'properly encodes a path with a query string' , function ( ) {
12
+ expect ( Path . encode ( '/my/short path?a=b&c=d' ) ) . toEqual ( '/my/short+path?a=b&c=d' ) ;
13
+ } ) ;
14
+ } ) ;
15
+
4
16
describe ( 'Path.extractParamNames' , function ( ) {
5
17
describe ( 'when a pattern contains no dynamic segments' , function ( ) {
6
18
it ( 'returns an empty array' , function ( ) {
You can’t perform that action at this time.
0 commit comments