Skip to content

Commit

Permalink
Fix bug where RTDB trigger for instances w/ "ref" in the db name were…
Browse files Browse the repository at this point in the history
… incorrectly parsed.

Fixes #1055
  • Loading branch information
rhodgkins committed Mar 11, 2022
1 parent f45e45f commit 0a1c7ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions 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).
16 changes: 16 additions & 0 deletions spec/v1/providers/database.spec.ts
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion src/providers/database.ts
Expand Up @@ -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
*
Expand All @@ -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(
Expand Down

0 comments on commit 0a1c7ab

Please sign in to comment.