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

Fix parsing image assets from a Markdown line along with other markup #7742

Merged
merged 1 commit into from
Jul 21, 2023

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Jul 21, 2023

Changes

Every regex that tries to match a substring with .* or .+ is guaranteed to be wrong. In this case, it was giving incorrect matches straddling multiple quoted attributes:

<img __ASTRO_IMAGE_="../assets/image.png"> and <a href="link">link</a>
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Fixes #7741.

Testing

Tested with the test case in #7741.

Docs

This is a pure bugfix that doesn’t need documentation.

Every regex that tries to match a substring with .* or .+ is
guaranteed to be wrong.  In this case, it was giving incorrect matches
straddling multiple quoted attributes:

    <img __ASTRO_IMAGE_="../assets/image.png"> and <a href="link">link</a>
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Fixes withastro#7741.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
@changeset-bot
Copy link

changeset-bot bot commented Jul 21, 2023

🦋 Changeset detected

Latest commit: 2bb2341

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 21, 2023
Copy link
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

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

Awesome, thank you! I still need to figure out a better way to do this one day, having to use a regex in the first place isn't amazing.

@Princesseuh Princesseuh merged commit e528526 into withastro:main Jul 21, 2023
@astrobot-houston astrobot-houston mentioned this pull request Jul 21, 2023
@andersk andersk deleted the updateImageReferences-regex branch July 21, 2023 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Referencing asset image on the same line as a Markdown link gives error: images[imagePath] is undefined
2 participants