From 39fc092ef536984cf8d33c473bcdbc7dc8274bf9 Mon Sep 17 00:00:00 2001 From: Rich Hodgkins Date: Thu, 10 Mar 2022 09:26:43 +0000 Subject: [PATCH 1/3] Failing test cases for #1055 --- spec/v1/providers/database.spec.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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', From da00b716589ae7a27fab88ecd424b20592737a09 Mon Sep 17 00:00:00 2001 From: Rich Hodgkins Date: Thu, 10 Mar 2022 09:38:52 +0000 Subject: [PATCH 2/3] Corrected regex for #1055 --- src/providers/database.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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( From b55be1066603c0a9a1d60668acdeeb5c2da1bf76 Mon Sep 17 00:00:00 2001 From: Rich Hodgkins Date: Fri, 11 Mar 2022 11:41:43 +0000 Subject: [PATCH 3/3] Changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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).