diff --git a/CHANGELOG.md b/CHANGELOG.md index c094d2168..939704fd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,2 @@ - Add support for more regions and memory for v2 functions (#1037). +- Fixes bug where some RTDB instance names were incorrectly parsed (#1056). diff --git a/spec/v1/providers/database.spec.ts b/spec/v1/providers/database.spec.ts index 21706b2d5..2ea1022e3 100644 --- a/spec/v1/providers/database.spec.ts +++ b/spec/v1/providers/database.spec.ts @@ -529,6 +529,22 @@ describe('Database Functions', () => { expect(path).to.equal('/bar'); }); + it('should return the correct instance and path strings if root path is /refs', () => { + const [instance, path] = database.extractInstanceAndPath( + 'projects/_/instances/foo/refs/refs' + ); + expect(instance).to.equal('https://foo.firebaseio.com'); + expect(path).to.equal('/refs'); + }); + + it('should return the correct instance and path strings if a child path contain /refs', () => { + const [instance, path] = database.extractInstanceAndPath( + 'projects/_/instances/foo/refs/root/refs' + ); + expect(instance).to.equal('https://foo.firebaseio.com'); + expect(path).to.equal('/root/refs'); + }); + it('should return the correct multi-region instance and path strings if domain is present', () => { const [instance, path] = database.extractInstanceAndPath( 'projects/_/instances/foo/refs/bar', diff --git a/src/providers/database.ts b/src/providers/database.ts index 53eb9ba12..e5f4d8ed3 100644 --- a/src/providers/database.ts +++ b/src/providers/database.ts @@ -307,6 +307,8 @@ export class RefBuilder { }; } +const resourceRegex = /^projects\/([^/]+)\/instances\/([a-zA-Z0-9-]+)\/refs(\/.+)?/; + /** * Utility function to extract database reference from resource string * @@ -320,7 +322,6 @@ export function extractInstanceAndPath( resource: string, domain = 'firebaseio.com' ) { - const resourceRegex = `projects/([^/]+)/instances/([a-zA-Z0-9\-^/]+)/refs(/.+)?`; const match = resource.match(new RegExp(resourceRegex)); if (!match) { throw new Error(