Skip to content

Commit 68e6e52

Browse files
Properly escape field paths
1 parent b87cfd1 commit 68e6e52

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

packages/firestore/src/model/path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export class FieldPath extends BasePath<FieldPath> {
265265
canonicalString(): string {
266266
return this.toArray()
267267
.map(str => {
268-
str = str.replace('\\', '\\\\').replace('`', '\\`');
268+
str = str.replace(/\\/g, '\\\\').replace(/`/g, '\\`');
269269
if (!FieldPath.isValidIdentifier(str)) {
270270
str = '`' + str + '`';
271271
}

packages/firestore/src/remote/rpc_error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export function mapCodeFromHttpStatus(status?: number): Code {
314314
* Code.UNKNOWN.
315315
*/
316316
export function mapCodeFromHttpResponseErrorStatus(status: string): Code {
317-
const serverError = status.toLowerCase().replace('_', '-');
317+
const serverError = status.toLowerCase().replace(/_/g, '-');
318318
return Object.values(Code).indexOf(serverError as Code) >= 0
319319
? (serverError as Code)
320320
: Code.UNKNOWN;

packages/firestore/test/unit/model/path.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ describe('Path', () => {
160160
expect(abc.isPrefixOf(ba)).to.equal(false);
161161
});
162162

163+
it('escaped FieldPath with segments', () => {
164+
const path = new FieldPath(['foo.`bar`']);
165+
expect(path.canonicalString()).to.equal('`foo.\\`bar\\``');
166+
});
167+
163168
it('can be constructed from field path.', () => {
164169
const path = FieldPath.fromServerFormat('foo\\..bar\\\\.baz');
165170
expect(path.toArray()).to.deep.equal(['foo.', 'bar\\', 'baz']);

0 commit comments

Comments
 (0)