Skip to content

Commit

Permalink
Merge pull request #2293 from hapijs/consider-changeless-forks
Browse files Browse the repository at this point in the history
Fix error on changeless forks. Fixes #2292.
  • Loading branch information
hueniverse committed Feb 12, 2020
2 parents a9b5c3c + e9f1865 commit 6ec7131
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ internals.fork = function (schema, id, replacement) {
};

const obj = exports.schema(schema, { each, ref: false });
return obj.$_mutateRebuild();
return obj ? obj.$_mutateRebuild() : schema;
};


Expand Down
8 changes: 8 additions & 0 deletions test/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ describe('Modify', () => {
Helper.equal(before.fork('x', (schema) => schema.min(10)), after);
});

it('preserves unchanged schemas', () => {

const before = Joi.object({ x: Joi.string().optional() });
const after = Joi.object({ x: Joi.string().optional() });

Helper.equal(before.fork('x', (schema) => schema.optional()), after);
});

it('adjusts reused schema in multiple places', () => {

const shared = Joi.number().id('x');
Expand Down

0 comments on commit 6ec7131

Please sign in to comment.