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 resource_link regex, make non-greedy #927

Merged
merged 3 commits into from
Jan 24, 2022
Merged

Conversation

ChristopherChudzicki
Copy link
Contributor

Before the regex was greedy so it would not stop at the end of the first resource_link. Two resource links on the same lin would be gobbled up as one.

The new regex is still pretty simple but will be fooled by resource_link titles that include literal " >}} values. This is a pretty edgy edge case. We could get around this in the future by escpaing quotations in the link titles and using a different regex (or parsing some other way). But right now the unescaped quotation characters are not causing any problems other than this, so lets keep this fix simple.

Pre-Flight checklist

  • Screenshots and design review for any changes that affect layout or styling
    • Desktop screenshots
  • Testing
    • Code is tested
    • Changes have been manually tested

What are the relevant tickets?

Fixes #917 and #903.

What's this PR do?

Fixes the regex that was turning resource_link shortcodes into HTM.

How should this be manually tested?

Screenshots (if appropriate)

Before / After
Screen Shot 2022-01-24 at 3 05 13 PM Screen Shot 2022-01-24 at 3 04 54 PM

@ChristopherChudzicki ChristopherChudzicki requested review from alicewriteswrongs and removed request for alicewriteswrongs January 24, 2022 20:21
Fixes #917 and #903.

Before the regex was greedy so it would not stop at the end of the first resource_link. Two resource links on the same lin would be gobbled up as one.

The new regex is still pretty simple but will be fooled by resource_link titles that include literal `" >}}` values. This is a pretty edgy edge case. We could get around this in the future by escpaing quotations in the link titles and using a different regex (or parsing some other way). But right now the unescaped quotation characters are not causing any problems other than this, so lets keep this fix simple.
)
})

it("[BUG] does not behave well if link title ends in backslash", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test was just to document the behavior #928 🤷

Copy link
Contributor

@alicewriteswrongs alicewriteswrongs left a comment

Choose a reason for hiding this comment

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

tested it out and it works great, just noticed one formatting thing

* Limitations:
* - gets fooled by label texts that include literal `" >}}` values. For
* example, < resource_link uuid123 "silly " >}} link" >}}.
*/
Copy link
Contributor

@alicewriteswrongs alicewriteswrongs Jan 24, 2022

Choose a reason for hiding this comment

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

I think you might have accidentally moved the regex and it's jsdoc comment between the ResourceLinkMarkdownSyntax class declaration and it's jsdoc comment here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh silly me. I've moved the regex mostly back up (but put it below the imports)

Copy link
Contributor

Choose a reason for hiding this comment

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

one more thing, and sorry I should have been more clear! but it would be good to put the block comment that you wrote for it above the variable declaration too, like this

/**
 * Here I can describe
 * What something does or doesn't
 * do through a haiku
 **/
const REGEX = /etc/

then various code tools will associate that comment with the REGEX variable as a documentation comment - for instance, in my editor if I ask about the type of a variable it will pop up a little window with type information and also print the associated comment, like this:

Screen Shot 2022-01-24 at 4 39 34 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neat—for some reason I never realized JSDoc comments worked for constants like they do for functions and classes... but why wouldn't they, I suppose.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, I don't know if they'll work like that for all documentation tools, but they seem to be well supported w/ typescript ecosystem tools at any rate! super handy to have them pop up when something is confusing me later (usually something I wrote originally haha)

Copy link
Contributor

@alicewriteswrongs alicewriteswrongs left a comment

Choose a reason for hiding this comment

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

lgtm!

@ChristopherChudzicki
Copy link
Contributor Author

Chris Chudzicki

@ChristopherChudzicki ChristopherChudzicki deleted the regex-fix branch January 27, 2022 14:39
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.

issue with resource link regex
2 participants