Skip to content

Commit

Permalink
Merge pull request #27511 from storybookjs/shilman/27510-wrap-project…
Browse files Browse the repository at this point in the history
…-tags

Tags: Fix unsafe project-level tags lookup
(cherry picked from commit 341904e)
  • Loading branch information
shilman authored and storybook-bot committed Jun 2, 2024
1 parent 64bd697 commit 0f696c5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions code/lib/core-server/src/utils/StoryIndexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,24 @@ export class StoryIndexGenerator {
const defaultTags = ['dev', 'test'];
const extraTags = this.options.docs.autodocs === true ? [AUTODOCS_TAG] : [];
if (previewCode) {
const projectAnnotations = loadConfig(previewCode).parse();
projectTags = projectAnnotations.getFieldValue(['tags']) ?? [];
try {
const projectAnnotations = loadConfig(previewCode).parse();
projectTags = projectAnnotations.getFieldValue(['tags']) ?? [];
} catch (err) {
once.warn(dedent`
Unable to parse tags from project configuration. If defined, tags should be specified inline, e.g.
export default {
tags: ['foo'],
}
---
Received:
${previewCode}
`);
}
}
return [...defaultTags, ...projectTags, ...extraTags];
}
Expand Down

0 comments on commit 0f696c5

Please sign in to comment.