Skip to content

Commit 7056ba7

Browse files
fix: correctly escape field paths with multiple backslashes or backticks (#2259) (#2261)
Co-authored-by: Albert Nisbet <[email protected]>
1 parent 3fd0de9 commit 7056ba7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

dev/src/path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ export class FieldPath extends Path<FieldPath> implements firestore.FieldPath {
672672
.map(str => {
673673
return UNESCAPED_FIELD_NAME_RE.test(str)
674674
? str
675-
: '`' + str.replace('\\', '\\\\').replace('`', '\\`') + '`';
675+
: '`' + str.replace(/\\/g, '\\\\').replace(/`/g, '\\`') + '`';
676676
})
677677
.join('.');
678678
}

dev/test/path.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,23 @@ describe('ResourcePath', () => {
6868

6969
describe('FieldPath', () => {
7070
it('encodes field names', () => {
71-
const components = [['foo'], ['foo', 'bar'], ['.', '`'], ['\\']];
72-
73-
const results = ['foo', 'foo.bar', '`.`.`\\``', '`\\\\`'];
71+
const components = [
72+
['foo'],
73+
['foo', 'bar'],
74+
['.', '`'],
75+
['\\'],
76+
['\\\\'],
77+
['``'],
78+
];
79+
80+
const results = [
81+
'foo',
82+
'foo.bar',
83+
'`.`.`\\``',
84+
'`\\\\`',
85+
'`\\\\\\\\`',
86+
'`\\`\\``',
87+
];
7488

7589
for (let i = 0; i < components.length; ++i) {
7690
expect(new FieldPath(...components[i]).toString()).to.equal(results[i]);

0 commit comments

Comments
 (0)