33using System . Collections . Specialized ;
44using System . IO ;
55using System . Net ;
6+ using System . Reflection ;
67using System . Text ;
78using System . Threading ;
89using System . Threading . Tasks ;
@@ -326,17 +327,21 @@ public void Iterate(IEnumerable<Task> asyncIterator, TaskCompletionSource<Connec
326327 recursiveBody ( null ) ;
327328 }
328329
329- private string _CreateUriString ( string path )
330+ private Uri _CreateUriString ( string path )
330331 {
331332 var s = this . _ConnectionSettings ;
332-
333+
334+
333335 if ( s . QueryStringParameters != null )
334336 {
335- var uri = new Uri ( s . Uri , path ) ;
336- var qs = s . QueryStringParameters . ToQueryString ( uri . Query . IsNullOrEmpty ( ) ? "?" : "&" ) ;
337+ var tempUri = new Uri ( s . Uri , path ) ;
338+ var qs = s . QueryStringParameters . ToQueryString ( tempUri . Query . IsNullOrEmpty ( ) ? "?" : "&" ) ;
337339 path += qs ;
338340 }
339-
341+ LeaveDotsAndSlashesEscaped ( s . Uri ) ;
342+ var uri = new Uri ( s . Uri , path ) ;
343+ LeaveDotsAndSlashesEscaped ( uri ) ;
344+ return uri ;
340345 var url = s . Uri . AbsoluteUri + path ;
341346 //WebRequest.Create will replace %2F with /
342347 //this is a 'security feature'
@@ -346,7 +351,39 @@ private string _CreateUriString(string path)
346351 //it won't barf.
347352 //If you manually set the config settings to NOT forefully unescape dots and slashes be sure to call
348353 //.SetDontDoubleEscapePathDotsAndSlashes() on the connection settings.
349- return this . _ConnectionSettings . DontDoubleEscapePathDotsAndSlashes ? url : url . Replace ( "%2F" , "%252F" ) ;
354+ //return );
355+
356+ //return this._ConnectionSettings.DontDoubleEscapePathDotsAndSlashes ? url : url.Replace("%2F", "%252F");
357+ }
358+
359+ // System.UriSyntaxFlags is internal, so let's duplicate the flag privately
360+ private const int UnEscapeDotsAndSlashes = 0x2000000 ;
361+
362+ public static void LeaveDotsAndSlashesEscaped ( Uri uri )
363+ {
364+ if ( uri == null )
365+ {
366+ throw new ArgumentNullException ( "uri" ) ;
367+ }
368+
369+ FieldInfo fieldInfo = uri . GetType ( ) . GetField ( "m_Syntax" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
370+ if ( fieldInfo == null )
371+ {
372+ throw new MissingFieldException ( "'m_Syntax' field not found" ) ;
373+ }
374+ object uriParser = fieldInfo . GetValue ( uri ) ;
375+
376+ fieldInfo = typeof ( UriParser ) . GetField ( "m_Flags" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
377+ if ( fieldInfo == null )
378+ {
379+ throw new MissingFieldException ( "'m_Flags' field not found" ) ;
380+ }
381+ object uriSyntaxFlags = fieldInfo . GetValue ( uriParser ) ;
382+
383+ // Clear the flag that we don't want
384+ uriSyntaxFlags = ( int ) uriSyntaxFlags & ~ UnEscapeDotsAndSlashes ;
385+
386+ fieldInfo . SetValue ( uriParser , uriSyntaxFlags ) ;
350387 }
351388 }
352389}
0 commit comments