Skip to content

Commit 4752181

Browse files
author
Nathan Gobinet
committed
Add test and prettier
1 parent f15ec8e commit 4752181

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/jsondiffpatch/src/formatters/jsonpatch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ class JSONFormatter extends BaseFormatter<JSONFormatterContext, Op[]> {
102102

103103
context.buildPath = function (path: (string | number)[]) {
104104
return path.map((path) => this.escapePath!(path)).join('/');
105-
}
106-
105+
};
106+
107107
context.escapePath = function (path: string | number) {
108108
if (typeof path !== 'string') return path.toString();
109109
if (path.indexOf('/') === -1 && path.indexOf('~') === -1) return path;
110110
return path.replace(/~/g, '~0').replace(/\//g, '~1');
111-
}
111+
};
112112
}
113113

114114
typeFormattterErrorFormatter(context: JSONFormatterContext, err: unknown) {

packages/jsondiffpatch/test/index.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,12 @@ describe('DiffPatcher', () => {
606606
});
607607
expectFormat(before, after, diff);
608608
});
609+
610+
it('should escape the property name', () => {
611+
expectFormat({ 'tree/item': 1 }, { 'tree/item': 2 }, [
612+
replaceOp('/tree~1item', 2),
613+
]);
614+
});
609615
});
610616

611617
describe('html', () => {

0 commit comments

Comments
 (0)