Skip to content

Commit

Permalink
fix(slugger): fix slugger crash due to title property
Browse files Browse the repository at this point in the history
the slugger would assume `title` to always be a `string`, which was an invalid assumption for
objects that have a `title` property declaration

fixes #196
  • Loading branch information
trieloff committed Jan 14, 2020
1 parent 66fa1d0 commit 4f0ab31
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 11 additions & 3 deletions lib/schemaProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ const handler = ({
return [...parent[symbols.titles], target.title];
}
// otherwise, it's just our own
return [target[keyword`title`]];
if (typeof target.title === 'string') {
return [target[keyword`title`]];
}
return [];
};

meta[symbols.resolve] = (target, prop, receiver) => (path) => {
Expand All @@ -80,8 +83,13 @@ const handler = ({
const parentslug = parent[symbols.slug];
const { title } = receiver;
const name = receiver[symbols.pointer].split('/').pop();
// eslint-disable-next-line no-param-reassign
receiver[myslug] = slugger.slug(`${parentslug}-${title || name}`);
if (typeof title === 'string') {
// eslint-disable-next-line no-param-reassign
receiver[myslug] = slugger.slug(`${parentslug}-${title || name}`);
} else {
// eslint-disable-next-line no-param-reassign
receiver[myslug] = slugger.slug(`${parentslug}-${name}`);
}
}
return receiver[myslug];
};
Expand Down
10 changes: 2 additions & 8 deletions test/markdownBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,8 @@ describe('Testing Markdown Builder: title', () => {
});

it('Meta Schema looks OK', () => {
assertMarkdown(results.title)
.fuzzy`## Not true Type
merged type ([Not true](not.md))
not
- [True](not-true.md "check type definition")`;
assertMarkdown(results.meta)
.fuzzy`defined in: [Meta](meta-definitions-meta-properties-title.md "https://ns.adobe.com/helix/pipeline/meta#/definitions/meta/properties/title")`;
});
});

Expand Down

0 comments on commit 4f0ab31

Please sign in to comment.