Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexer: Escape special characters in storyImport regex #22545

Merged
merged 7 commits into from
May 13, 2024

Conversation

VojGin
Copy link

@VojGin VojGin commented May 13, 2023

Closes #

No issue in evidence

What I did

I had a problem with using <Meta of{...} /> inside MDX file.

238134010-5c70d6c1-8dec-40ae-8e93-fc7a27144c3c

It always resulted in this error and I didn't know why.

Turns out the problem was the string literal inserting in the Regex as it did not escape special characters from the file path thus it could never match.

Usually paths have slashes / which work fine without escaping. But I had a plus sign + in my path. A plus sign is regex modifier, thus the regex stopped working.

How to test

  1. Run unfixed storybook on a project with plus sign + somewhere in the absolute path and try to include some MDX containing <Meta of={...} />

Such as this one:

{/* ButtonDocs.mdx */}

import { Meta, Story } from '@storybook/blocks';
import * as ButtonStories from './Button.stories';

<Meta of={ButtonStories} />
  1. It will result in an error.

  2. You can compare it then with the fixed version then. The error is gone.

Checklist

  • Make sure your changes are tested (stories and/or unit, integration, or end-to-end tests)
  • Make sure to add/update documentation regarding your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Maintainers

  • If this PR should be tested against many or all sandboxes,
    make sure to add the ci:merged or ci:daily GH label to it.
  • Make sure this PR contains one of the labels below.

["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]

@VojGin VojGin marked this pull request as ready for review May 13, 2023 12:52
@shilman
Copy link
Member

shilman commented May 15, 2023

Also probably related #22110

@ndelangen ndelangen changed the title Escape special characters in storyImport regex Indexer: Escape special characters in storyImport regex Nov 28, 2023
Comment on lines +260 to +262
fileName.match(
new RegExp(`^${storyImport.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(\\.[^.]+)?$`)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the only significant change? the rest is more cleanup/linting?

Copy link

nx-cloud bot commented Mar 26, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 1caa075. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@valentinpalkovic valentinpalkovic removed their request for review April 4, 2024 09:03
Copy link
Contributor

@JReinhold JReinhold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change looks good, GPT-4 conjured up the exact same string replacement, which obviously means this is pristine quality! 💅

@JReinhold JReinhold added core and removed mdx labels May 7, 2024
@JReinhold
Copy link
Contributor

Most likely also fixes #25114

@shilman shilman merged commit fc6ccd8 into storybookjs:next May 13, 2024
56 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants