Skip to content

Commit 0a1c7ab

Browse files
authored
Fix bug where RTDB trigger for instances w/ "ref" in the db name were incorrectly parsed.
Fixes #1055
1 parent f45e45f commit 0a1c7ab

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- Add support for more regions and memory for v2 functions (#1037).
2+
- Fixes bug where some RTDB instance names were incorrectly parsed (#1056).

spec/v1/providers/database.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,22 @@ describe('Database Functions', () => {
529529
expect(path).to.equal('/bar');
530530
});
531531

532+
it('should return the correct instance and path strings if root path is /refs', () => {
533+
const [instance, path] = database.extractInstanceAndPath(
534+
'projects/_/instances/foo/refs/refs'
535+
);
536+
expect(instance).to.equal('https://foo.firebaseio.com');
537+
expect(path).to.equal('/refs');
538+
});
539+
540+
it('should return the correct instance and path strings if a child path contain /refs', () => {
541+
const [instance, path] = database.extractInstanceAndPath(
542+
'projects/_/instances/foo/refs/root/refs'
543+
);
544+
expect(instance).to.equal('https://foo.firebaseio.com');
545+
expect(path).to.equal('/root/refs');
546+
});
547+
532548
it('should return the correct multi-region instance and path strings if domain is present', () => {
533549
const [instance, path] = database.extractInstanceAndPath(
534550
'projects/_/instances/foo/refs/bar',

src/providers/database.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ export class RefBuilder {
307307
};
308308
}
309309

310+
const resourceRegex = /^projects\/([^/]+)\/instances\/([a-zA-Z0-9-]+)\/refs(\/.+)?/;
311+
310312
/**
311313
* Utility function to extract database reference from resource string
312314
*
@@ -320,7 +322,6 @@ export function extractInstanceAndPath(
320322
resource: string,
321323
domain = 'firebaseio.com'
322324
) {
323-
const resourceRegex = `projects/([^/]+)/instances/([a-zA-Z0-9\-^/]+)/refs(/.+)?`;
324325
const match = resource.match(new RegExp(resourceRegex));
325326
if (!match) {
326327
throw new Error(

0 commit comments

Comments
 (0)