Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #1055 #1056

Merged
merged 3 commits into from Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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');
});

Comment on lines +532 to +547
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ Thank you for adding tests!

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