Skip to content

Commit 89b9a39

Browse files
Allow newlines in Resource Paths (#114)
1 parent 603f71d commit 89b9a39

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

handwritten/firestore/src/path.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const validate = require('./validate')();
2727
*
2828
* @type {RegExp}
2929
*/
30-
const RESOURCE_PATH_RE = /^projects\/([^/]*)\/databases\/([^/]*)(?:\/documents\/)?(.*)$/;
30+
const RESOURCE_PATH_RE =
31+
// Note: [\s\S] matches all characters including newlines.
32+
/^projects\/([^/]*)\/databases\/([^/]*)(?:\/documents\/)?([\s\S]*)$/;
3133

3234
/*!
3335
* A regular expression to verify whether a field name can be passed to the
@@ -295,6 +297,7 @@ class ResourcePath extends Path {
295297
get databaseId() {
296298
return this._databaseId;
297299
}
300+
298301
/**
299302
* Returns true if the given string can be used as a relative or absolute
300303
* resource path.

handwritten/firestore/test/path.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ describe('ResourcePath', function() {
6161
);
6262
}, /Resource name 'projects\/project\/databases' is not valid\./);
6363
});
64+
65+
it('accepts newlines', function() {
66+
const path = ResourcePath.fromSlashSeparatedString(
67+
`${DATABASE_ROOT}/documents/foo\nbar`
68+
);
69+
assert.equal(path.formattedName, `${DATABASE_ROOT}/documents/foo\nbar`);
70+
});
6471
});
6572

6673
describe('FieldPath', function() {

0 commit comments

Comments
 (0)