[Mono-devel-list] Re: ExpandEnvironmentVariables fix

Fawad Halim fawad at fawad.net
Sun Oct 24 17:03:41 EDT 2004


I've attached a nicely formatted copy with plenty of comments.

Regards
-fawad

Fawad Halim wrote:
> Hi,
>     Attached is a patch to fix the behavior of 
> ExpandEnvironmentVariables as described in bug #64995. Ok to commit?
> 
> Regards
> -fawad
> 
> 
> ------------------------------------------------------------------------
> 
> Index: class/corlib/System/Environment.cs
> ===================================================================
> RCS file: /cvs/public/mcs/class/corlib/System/Environment.cs,v
> retrieving revision 1.88
> diff -u -r1.88 Environment.cs
> --- class/corlib/System/Environment.cs	11 Oct 2004 00:14:50 -0000	1.88
> +++ class/corlib/System/Environment.cs	17 Oct 2004 17:14:35 -0000
> @@ -278,7 +278,7 @@
>  		/// Substitute environment variables in the argument "name"
>  		/// </summary>
>  		public static string ExpandEnvironmentVariables (string name)
> -		{
> +		{	
>  			if (name == null)
>  				throw new ArgumentNullException ("name");
>  
> @@ -309,25 +309,26 @@
>  				if (value == null) {
>  					result.Append ('%');
>  					result.Append (var);
> -					result.Append ('%');
> +					off2--;
>  				} else {
>  					result.Append (value);
>  				}
> -
> -				if (off2 + 1 == len) {
> -					off1 = off2;
> -					off2 = -1;
> -				} else {
> -					off1 = off2 + 1;
> -					off2 = (off1 + 1 == len) ? -1 : name.IndexOf ('%', off1 + 1);
> -				}
> -
> -			} while (off2 != -1);
> -
> -			if (off1 + 1 < len)
> -				result.Append (name.Substring (off1));
> -
> +				int oldOff2=off2;
> +				off1=name.IndexOf ('%', off2 + 1);
> +				off2=(off1==-1||off2>len-1)?-1:name.IndexOf ('%', off1 + 1);
> +				int textLen;
> +				if(off1==-1||off2==-1)
> +					textLen=len-oldOff2-1;
> +				else if(value!=null)
> +					textLen=off1-oldOff2-1;
> +				else
> +					textLen=off1-oldOff2;
> +				if(off1>=oldOff2||off1==-1)
> +					result.Append(name.Substring(oldOff2+1,textLen));
> +			} while (off2>-1&&off2<len);
> +				
>  			return result.ToString ();
> +
>  		}
>  
>  		/// <summary>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EnvVars.diff
Type: text/x-patch
Size: 2090 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20041024/d531d602/attachment.bin 


More information about the Mono-devel-list mailing list