This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed
tests/ServiceStack.Text.Tests Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,12 @@ public static string ResolvePaths(this string path)
137
137
if ( path == null || path . IndexOfAny ( "./" , "/." ) == - 1 )
138
138
return path ;
139
139
140
- var parts = path . Split ( '/' ) . ToList ( ) ;
140
+ var schemePos = path . IndexOf ( "://" , StringComparison . Ordinal ) ;
141
+ var prefix = schemePos >= 0
142
+ ? path . Substring ( 0 , schemePos + 3 )
143
+ : "" ;
144
+
145
+ var parts = path . Substring ( prefix . Length ) . Split ( '/' ) . ToList ( ) ;
141
146
var combinedPaths = new List < string > ( ) ;
142
147
foreach ( var part in parts )
143
148
{
@@ -151,12 +156,12 @@ public static string ResolvePaths(this string path)
151
156
}
152
157
153
158
var resolvedPath = string . Join ( "/" , combinedPaths ) ;
154
- if ( path [ 0 ] == '/' )
159
+ if ( path [ 0 ] == '/' && prefix . Length == 0 )
155
160
resolvedPath = '/' + resolvedPath ;
156
161
157
- return path [ path . Length - 1 ] == '/'
158
- ? resolvedPath + '/'
159
- : resolvedPath ;
162
+ return path [ path . Length - 1 ] == '/' && resolvedPath . Length > 0
163
+ ? prefix + resolvedPath + '/'
164
+ : prefix + resolvedPath ;
160
165
}
161
166
162
167
public static string [ ] ToStrings ( object [ ] thesePaths )
Original file line number Diff line number Diff line change @@ -49,5 +49,22 @@ public void Can_resolve_paths()
49
49
Assert . That ( "a/../../b" . ResolvePaths ( ) , Is . EqualTo ( "../b" ) ) ;
50
50
}
51
51
52
+ [ Test ]
53
+ public void Can_resolve_paths_with_urls ( )
54
+ {
55
+ Assert . That ( "http://example.org/a/b/../" . ResolvePaths ( ) , Is . EqualTo ( "http://example.org/a/" ) ) ;
56
+ Assert . That ( "http://example.org/a/b/.." . ResolvePaths ( ) , Is . EqualTo ( "http://example.org/a" ) ) ;
57
+
58
+ Assert . That ( "http://example.org/a/../b" . ResolvePaths ( ) , Is . EqualTo ( "http://example.org/b" ) ) ;
59
+ Assert . That ( "http://example.org/a/../b/./c" . ResolvePaths ( ) , Is . EqualTo ( "http://example.org/b/c" ) ) ;
60
+ Assert . That ( "http://example.org/a/b/c/d/../.." . ResolvePaths ( ) , Is . EqualTo ( "http://example.org/a/b" ) ) ;
61
+ Assert . That ( "http://example.org/a/b/../../c/d" . ResolvePaths ( ) , Is . EqualTo ( "http://example.org/c/d" ) ) ;
62
+
63
+ Assert . That ( "http://example.org/a/.." . ResolvePaths ( ) , Is . EqualTo ( "http://example.org" ) ) ;
64
+ Assert . That ( "http://example.org/a/../.." . ResolvePaths ( ) , Is . EqualTo ( "http://" ) ) ;
65
+ Assert . That ( "http://example.org/a/../../" . ResolvePaths ( ) , Is . EqualTo ( "http://" ) ) ;
66
+ Assert . That ( "http://example.org/a/../../b" . ResolvePaths ( ) , Is . EqualTo ( "http://b" ) ) ;
67
+ }
68
+
52
69
}
53
70
}
You can’t perform that action at this time.
0 commit comments