Skip to content

Commit 4f0ab31

Browse files
committed
fix(slugger): fix slugger crash due to title property
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
1 parent 66fa1d0 commit 4f0ab31

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/schemaProxy.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ const handler = ({
5454
return [...parent[symbols.titles], target.title];
5555
}
5656
// otherwise, it's just our own
57-
return [target[keyword`title`]];
57+
if (typeof target.title === 'string') {
58+
return [target[keyword`title`]];
59+
}
60+
return [];
5861
};
5962

6063
meta[symbols.resolve] = (target, prop, receiver) => (path) => {
@@ -80,8 +83,13 @@ const handler = ({
8083
const parentslug = parent[symbols.slug];
8184
const { title } = receiver;
8285
const name = receiver[symbols.pointer].split('/').pop();
83-
// eslint-disable-next-line no-param-reassign
84-
receiver[myslug] = slugger.slug(`${parentslug}-${title || name}`);
86+
if (typeof title === 'string') {
87+
// eslint-disable-next-line no-param-reassign
88+
receiver[myslug] = slugger.slug(`${parentslug}-${title || name}`);
89+
} else {
90+
// eslint-disable-next-line no-param-reassign
91+
receiver[myslug] = slugger.slug(`${parentslug}-${name}`);
92+
}
8593
}
8694
return receiver[myslug];
8795
};

test/markdownBuilder.test.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,8 @@ describe('Testing Markdown Builder: title', () => {
7272
});
7373

7474
it('Meta Schema looks OK', () => {
75-
assertMarkdown(results.title)
76-
.fuzzy`## Not true Type
77-
78-
merged type ([Not true](not.md))
79-
80-
not
81-
82-
- [True](not-true.md "check type definition")`;
75+
assertMarkdown(results.meta)
76+
.fuzzy`defined in: [Meta](meta-definitions-meta-properties-title.md "https://ns.adobe.com/helix/pipeline/meta#/definitions/meta/properties/title")`;
8377
});
8478
});
8579

0 commit comments

Comments
 (0)