Skip to content

Commit 768bb57

Browse files
committed
fix: pr feedback
1 parent f84c1ff commit 768bb57

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/pointer.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as url from "./util/url.js";
55
import { JSONParserError, InvalidPointerError, MissingPointerError, isHandledError } from "./util/errors.js";
66
import type { JSONSchema } from "./types";
77

8+
export const nullSymbol = Symbol('null');
9+
810
const slashes = /\//g;
911
const tildes = /~/g;
1012
const escapedSlash = /~1/g;
@@ -125,7 +127,9 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
125127
// actually instead pointing to an existing `null` value then we should use that
126128
// `null` value.
127129
if (token in this.value && this.value[token] === null) {
128-
this.value = null;
130+
// We use a `null` symbol for internal tracking to differntiate between a general `null`
131+
// value and our expected `null` value.
132+
this.value = nullSymbol;
129133
continue;
130134
}
131135

lib/ref.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Pointer from "./pointer.js";
1+
import Pointer, { nullSymbol } from "./pointer.js";
22
import type { JSONParserError, MissingPointerError, ParserError, ResolverError } from "./util/errors.js";
33
import { InvalidPointerError, isHandledError, normalizeError } from "./util/errors.js";
44
import { safePointerToPath, stripHash, getHash } from "./util/url.js";
@@ -119,7 +119,12 @@ class $Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOpt
119119
resolve(path: string, options?: O, friendlyPath?: string, pathFromRoot?: string) {
120120
const pointer = new Pointer<S, O>(this, path, friendlyPath);
121121
try {
122-
return pointer.resolve(this.value, options, pathFromRoot);
122+
const resolved = pointer.resolve(this.value, options, pathFromRoot);
123+
if (resolved.value === nullSymbol) {
124+
resolved.value = null;
125+
}
126+
127+
return resolved;
123128
} catch (err: any) {
124129
if (!options || !options.continueOnError || !isHandledError(err)) {
125130
throw err;
@@ -148,6 +153,9 @@ class $Ref<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOpt
148153
set(path: string, value: any) {
149154
const pointer = new Pointer(this, path);
150155
this.value = pointer.set(this.value, value);
156+
if (this.value === nullSymbol) {
157+
this.value = null;
158+
}
151159
}
152160

153161
/**

0 commit comments

Comments
 (0)