Skip to content

Commit

Permalink
Allow newlines in Resource Paths (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Jan 24, 2018
1 parent 5be8477 commit 19c3a15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/path.js
Expand Up @@ -27,7 +27,9 @@ const validate = require('./validate')();
*
* @type {RegExp}
*/
const RESOURCE_PATH_RE = /^projects\/([^/]*)\/databases\/([^/]*)(?:\/documents\/)?(.*)$/;
const RESOURCE_PATH_RE =
// Note: [\s\S] matches all characters including newlines.
/^projects\/([^/]*)\/databases\/([^/]*)(?:\/documents\/)?([\s\S]*)$/;

/*!
* A regular expression to verify whether a field name can be passed to the
Expand Down Expand Up @@ -295,6 +297,7 @@ class ResourcePath extends Path {
get databaseId() {
return this._databaseId;
}

/**
* Returns true if the given string can be used as a relative or absolute
* resource path.
Expand Down
7 changes: 7 additions & 0 deletions test/path.js
Expand Up @@ -61,6 +61,13 @@ describe('ResourcePath', function() {
);
}, /Resource name 'projects\/project\/databases' is not valid\./);
});

it('accepts newlines', function() {
const path = ResourcePath.fromSlashSeparatedString(
`${DATABASE_ROOT}/documents/foo\nbar`
);
assert.equal(path.formattedName, `${DATABASE_ROOT}/documents/foo\nbar`);
});
});

describe('FieldPath', function() {
Expand Down

0 comments on commit 19c3a15

Please sign in to comment.