* Regex.cs (Escape, Unescape): Add null checks.
(validate_options): Add ECMAScript option checks.
(Replace, Split): Add a few bounds checks.
svn path=/trunk/mcs/; revision=141459
+2009-09-07 Raja R Harinath <harinath@hurrynot.org>
+
+ * Regex.cs (Escape, Unescape): Add null checks.
+ (validate_options): Add ECMAScript option checks.
+ (Replace, Split): Add a few bounds checks.
+
2009-09-07 Raja R Harinath <harinath@hurrynot.org>
Add some null checks and bounds checks.
public static string Escape (string str)
{
+ if (str == null)
+ throw new ArgumentNullException ("str");
return Parser.Escape (str);
}
public static string Unescape (string str)
{
+ if (str == null)
+ throw new ArgumentNullException ("str");
return Parser.Unescape (str);
}
RegexOptions.RightToLeft |
RegexOptions.ECMAScript |
RegexOptions.CultureInvariant;
+
+ const RegexOptions ecmaopts =
+ RegexOptions.IgnoreCase |
+ RegexOptions.Multiline |
+#if !NET_2_1
+ RegexOptions.Compiled |
+#endif
+ RegexOptions.ECMAScript;
+
if ((options & ~allopts) != 0)
throw new ArgumentOutOfRangeException ("options");
+ if ((options & RegexOptions.ECMAScript) != 0 && (options & ~ecmaopts) != 0)
+ throw new ArgumentOutOfRangeException ("options");
}
#if !TARGET_JVM
throw new ArgumentNullException ("evaluator");
if (count < -1)
throw new ArgumentOutOfRangeException ("count");
+ if (startat < 0 || startat > input.Length)
+ throw new ArgumentOutOfRangeException ("startat");
BaseMachine m = (BaseMachine)CreateMachine ();
throw new ArgumentNullException ("replacement");
if (count < -1)
throw new ArgumentOutOfRangeException ("count");
+ if (startat < 0 || startat > input.Length)
+ throw new ArgumentOutOfRangeException ("startat");
return CreateMachine ().Replace (this, input, replacement, count, startat);
}
{
if (input == null)
throw new ArgumentNullException ("input");
+ if (count < 0)
+ throw new ArgumentOutOfRangeException ("count");
+ if (startat < 0 || startat > input.Length)
+ throw new ArgumentOutOfRangeException ("startat");
+
return CreateMachine ().Split (this, input, count, startat);
}
{
new Regex ("foo", (RegexOptions) Int32.MaxValue);
}
+
+ [Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
+ public void InvalidOptions2 ()
+ {
+ new Regex ("foo", RegexOptions.ECMAScript | RegexOptions.RightToLeft);
+ }
[Test]
public void Unescape ()
r.Replace ("string", m, 0, 0);
}
+ [Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
+ public void Replace_InvalidCount ()
+ {
+ Regex.Replace ("foo", "foo|bar", "baz", -4);
+ }
+
+ [Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
+ public void Replace_InvalidStart ()
+ {
+ Regex.Replace ("foo", "foo|bar", "baz", 1, -4);
+ }
+
[Test, ExpectedException (typeof (ArgumentNullException))]
public void Split_InputNull1 ()
{
Regex.Split (null, "^.*$", RegexOptions.RightToLeft);
}
+ [Test, ExpectedException (typeof (ArgumentNullException))]
+ public void Split_InvalidCount ()
+ {
+ Regex.Split (null, "^.*$", -4);
+ }
+
+ [Test, ExpectedException (typeof (ArgumentNullException))]
+ public void Split_InvalidCount ()
+ {
+ Regex.Split (null, "^.*$", 1, -4);
+ }
+
+ [Test, ExpectedException (typeof (ArgumentNullException))]
+ public void Escape_Null ()
+ {
+ Regex.Escape (null);
+ }
+
+ [Test, ExpectedException (typeof (ArgumentNullException))]
+ public void Unescape_Null ()
+ {
+ Regex.Unescape (null);
+ }
+
static string story =
"Two little dragons lived in the forest\n" +
"They spent their days collecting honey suckle,\n" +