diff --git a/src/util.js b/src/util.js index 9720f24f444..11a79f95eb4 100644 --- a/src/util.js +++ b/src/util.js @@ -191,7 +191,7 @@ export function validateCouchDBString(name) { ) return true; - const regStr = '^[a-z][a-z0-9]*$'; + const regStr = '^[a-z][_$a-z0-9]*$'; const reg = new RegExp(regStr); if (!name.match(reg)) { throw new RxError.newRxError('UT2', { diff --git a/test/unit/util.test.js b/test/unit/util.test.js index 05e8205e905..68db06f8231 100644 --- a/test/unit/util.test.js +++ b/test/unit/util.test.js @@ -65,6 +65,15 @@ describe('util.test.js', () => { it('should validate a normal string', () => { util.validateCouchDBString('foobar'); }); + it('should allow _ and $ after the first character', () => { + util.validateCouchDBString('foo_bar'); + util.validateCouchDBString('foobar_'); + util.validateCouchDBString('foobar$'); + } ); + it('should not allow _ and $ as first character', () => { + assert.throws( () => util.validateCouchDBString('$foobar'), { code: 'UT2' } ); + assert.throws( () => util.validateCouchDBString('_foobar'), { code: 'UT2' } ); + } ); it('should validate foldernames', () => { util.validateCouchDBString('./foobar'); // unix util.validateCouchDBString('.\\foobar'); //windows