This repository was archived by the owner on Jul 13, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -224,6 +224,19 @@ describe('resolver', () => {
224224 expect ( resolved . result . hello ) . toBe ( 'world' ) ;
225225 } ) ;
226226
227+ test ( 'should resolve json pointers pointing to falsy values' , async ( ) => {
228+ const source = {
229+ hello : {
230+ $ref : '#/word' ,
231+ } ,
232+ word : '' ,
233+ } ;
234+
235+ const resolver = new Resolver ( ) ;
236+ const resolved = await resolver . resolve ( source ) ;
237+ expect ( resolved . result . hello ) . toBe ( '' ) ;
238+ } ) ;
239+
227240 test ( 'should only resolve valid $refs' , async ( ) => {
228241 const source = {
229242 hello : {
@@ -526,6 +539,34 @@ describe('resolver', () => {
526539 expect ( resolved . result ) . toEqual ( source ) ;
527540 } ) ;
528541
542+ test ( 'should resolve jsonPointer pointing to remote falsy values' , async ( ) => {
543+ const source = {
544+ root : {
545+ $ref : 'custom://whatever#/entry' ,
546+ } ,
547+ } ;
548+
549+ const reader : Types . IResolver = {
550+ async resolve ( ) : Promise < any > {
551+ return {
552+ entry : 0 ,
553+ } ;
554+ } ,
555+ } ;
556+
557+ const resolver = new Resolver ( {
558+ resolvers : {
559+ custom : reader ,
560+ } ,
561+ } ) ;
562+
563+ const resolved = await resolver . resolve ( source ) ;
564+
565+ expect ( resolved . result ) . toEqual ( {
566+ root : 0 ,
567+ } ) ;
568+ } ) ;
569+
529570 test ( 'should support not resolving authorities' , async ( ) => {
530571 const data = {
531572 hello : 'world' ,
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ export class ResolveRunner implements Types.IResolveRunner {
109109 resolved . result = get ( resolved . result , targetPath ) ;
110110 }
111111
112- if ( ! resolved . result ) {
112+ if ( resolved . result === void 0 ) {
113113 resolved . errors . push ( {
114114 code : 'POINTER_MISSING' ,
115115 message : `'${ jsonPointer } ' does not exist @ '${ this . baseUri . toString ( ) } '` ,
@@ -157,7 +157,7 @@ export class ResolveRunner implements Types.IResolveRunner {
157157 resolved . errors = resolved . errors . concat ( r . resolved . errors ) ;
158158 }
159159
160- if ( ! r . resolved . result ) continue ;
160+ if ( r . resolved . result === void 0 ) continue ;
161161
162162 this . _source = produce ( this . _source , ( draft : any ) => {
163163 if ( r . resolved ) {
@@ -207,7 +207,7 @@ export class ResolveRunner implements Types.IResolveRunner {
207207
208208 resolved . refMap [ pathToPointer ( dependantPath ) ] = pathToPointer ( pointerPath ) ;
209209
210- if ( val ) {
210+ if ( val !== void 0 ) {
211211 set ( draft , dependantPath , val ) ;
212212 } else {
213213 resolved . errors . push ( {
You can’t perform that action at this time.
0 commit comments