[Mono-bugs] [Bug 39105][Nor] New - System.Text.RegularExpressions.CategoryUtils.CategoryFromName fails for one-letter categories
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
Wed, 5 Mar 2003 10:24:31 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by mathias.hasselmann@gmx.de.
http://bugzilla.ximian.com/show_bug.cgi?id=39105
--- shadow/39105 Wed Mar 5 10:24:31 2003
+++ shadow/39105.tmp.718 Wed Mar 5 10:24:31 2003
@@ -0,0 +1,43 @@
+Bug#: 39105
+Product: Mono/Class Libraries
+Version: unspecified
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: mathias.hasselmann@gmx.de
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: System.Text.RegularExpressions.CategoryUtils.CategoryFromName fails for one-letter categories
+
+Calling
+'System.Text.RegularExpressions.CategoryUtils.CategoryFromName("L");'
+returns 'System.Text.RegularExpressions.Category.None' instead of the
+considered 'System.Text.RegularExpressions.Category.UnicodeL'. This causes
+problems when parsing regular expressions containing the Unicode reference
+'\p{L}'.
+
+Reason is the invalid assumtion that strings passed to CategoryFromName
+always have a lenght of at least two characters:
+
+public static Category CategoryFromName (string name) {
+ try {
+ if (name.Substring (0, 2).Equals ("Is")) // remove prefix from block range
+ ~~~~~~~~~~~~~~~~~~~~~ <-- GOSH!
+ name = name.Substring (2);
+
+ return (Category)Enum.Parse (typeof (Category), "Unicode" + name);
+ }
+ catch (ArgumentException) {
+ return Category.None;
+ }
+}
+
+Fix: Replace 'if (name.Substring (0, 2).Equals ("Is"))' by 'if (name.Length
+> 2 && name.Substring (0, 2).Equals ("Is"))'