Improve handling of non-ascii collection names

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Gone away
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Storage
    • ALL
    • Hide

      The following test code triggers a failure when it gets to 0x7f:

      (function() {                                                                   
          "use strict";                                                               
                                                                                      
          let illegal_names = new Set();                                              
          illegal_names.add("$");                                                     
          illegal_names.add(".");                                                     
                                                                                      
          function testCreateCollectionWithName(coll_name) {                          
              // Cleanup from previous runs                                           
              let coll = db.getCollection(coll_name);                                 
                                                                                      
              // We should be able to create a collection with any UTF8 name          
              assert.commandWorked(db.createCollection(coll_name));                   
              coll = db.getCollection(coll_name);                                     
              coll.insert( { x : 1 } );                                               
              coll.findOne();                                                         
          }                                                                           
                                                                                      
          for (var i = 1; i < 256; i++) {                                             
              print("Name: " + i + " code: " + String.fromCharCode(i));               
              if (!illegal_names.has(String.fromCharCode(i))) {                       
                  testCreateCollectionWithName(String.fromCharCode(i));               
              }                                                                       
          }                                                                           
      })();      
       
      Show
      The following test code triggers a failure when it gets to 0x7f: (function() {                                                                      "use strict" ;                                                                                                                                                 let illegal_names = new Set();                                                 illegal_names.add( "$" );                                                        illegal_names.add( "." );                                                                                                                                       function testCreateCollectionWithName(coll_name) {                                 // Cleanup from previous runs                                                  let coll = db.getCollection(coll_name);                                                                                                                       // We should be able to create a collection with any UTF8 name                 assert .commandWorked(db.createCollection(coll_name));                          coll = db.getCollection(coll_name);                                            coll.insert( { x : 1 } );                                                      coll.findOne();                                                            }                                                                                                                                                             for ( var i = 1; i < 256; i++) {                                                    print( "Name: " + i + " code: " + String .fromCharCode(i));                      if (!illegal_names.has( String .fromCharCode(i))) {                                  testCreateCollectionWithName( String .fromCharCode(i));                      }                                                                          }                                                                          })();      
    • Execution Team 2019-09-23, Execution Team 2019-10-07, Execution Team 2021-06-14
    • 21
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Creating a collection with a UTF8 character out of the ASCII range can result in an unhelpful error. For example, creating a collection called '\x7f' (i.e: the delete character), results in the following error message:

      WT_SESSION.create: Error parsing 'type=file,internal_page_max=16k,leaf_page_max=16k,checksum=on,prefix_compression=true,block_compressor=,,,,key_format=u,value_format=u,app_metadata=(formatVersion=8,infoObj={ "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test." }),log=(enabled=true)' at offset 237: Unexpected character: Invalid argument 

      MongoDB should handle such collection names more elegantly. Either disallowing them similar to $ and {{.}}or allowing their creation without error.

            Assignee:
            Gregory Wlodarek
            Reporter:
            Alexander Gorrod
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: