From ed6a312500d27cdd26e013d83f3e513804be0093 Mon Sep 17 00:00:00 2001 From: Justin Dearing Date: Tue, 12 Oct 2010 14:36:33 -0400 Subject: [PATCH] Allow mixed case database names. Use more detailed error messages describing why a database name is invalid. [Patch submitted by Justin Dearing]. --- BsonLibrary/Properties/AssemblyInfo.cs | 2 +- CSharpDriver/Core/MongoDatabase.cs | 15 ++++++++------- CSharpDriver/Properties/AssemblyInfo.cs | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/BsonLibrary/Properties/AssemblyInfo.cs b/BsonLibrary/Properties/AssemblyInfo.cs index 3c8c6bef8e..300619ac7f 100644 --- a/BsonLibrary/Properties/AssemblyInfo.cs +++ b/BsonLibrary/Properties/AssemblyInfo.cs @@ -47,4 +47,4 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.5.0.3936")] +[assembly: AssemblyVersion("0.5.0.*")] diff --git a/CSharpDriver/Core/MongoDatabase.cs b/CSharpDriver/Core/MongoDatabase.cs index 2f187255b3..17e46154a3 100644 --- a/CSharpDriver/Core/MongoDatabase.cs +++ b/CSharpDriver/Core/MongoDatabase.cs @@ -328,13 +328,14 @@ namespace MongoDB.CSharpDriver { if (name == null) { throw new ArgumentNullException("name"); } - if ( - name == "" || - name.IndexOfAny(new char[] { '\0', ' ', '.', '$', '/', '\\' }) != -1 || - name != name.ToLower() || - Encoding.UTF8.GetBytes(name).Length > 64 - ) { - throw new ArgumentException("Invalid database name", "name"); + if (name == "") { + throw new ArgumentException("Database name is empty"); + } + if (name.IndexOfAny(new char[] { '\0', ' ', '.', '$', '/', '\\' }) != -1) { + throw new ArgumentException("Database name cannot contain the following special characters: null, space, period, $, / or \\"); + } + if (Encoding.UTF8.GetBytes(name).Length > 64) { + throw new ArgumentException("Database name cannot exceed 64 bytes (after encoding to UTF8)"); } } #endregion diff --git a/CSharpDriver/Properties/AssemblyInfo.cs b/CSharpDriver/Properties/AssemblyInfo.cs index 672f3b89bc..12a6d1eaac 100644 --- a/CSharpDriver/Properties/AssemblyInfo.cs +++ b/CSharpDriver/Properties/AssemblyInfo.cs @@ -47,4 +47,4 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.5.0.3936")] +[assembly: AssemblyVersion("0.5.0.*")]