Skip to content

Commit

Permalink
Disable GitHub flavored Markdown when lexing (#2317)
Browse files Browse the repository at this point in the history
`marked` has GitHub flavored Markdown enabled by default, but we don't
support GitHub flavored Markdown in the UI. This makes the validation
stricter than it needs to be. This PR fixes that by disabling GitHub
flavored Markdown when lexing.
  • Loading branch information
FrederikBolding authored Apr 9, 2024
1 parent b2520f3 commit 6f9ca36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions packages/snaps-utils/src/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ describe('validateTextLinks', () => {
).not.toThrow();
});

it('passes for non-links', () => {
expect(() =>
validateTextLinks('Hello **http://localhost:3000**', () => false),
).not.toThrow();
});

it('throws an error if an invalid link is found in text', () => {
expect(() =>
validateTextLinks('[test](http://foo.bar)', () => false),
Expand All @@ -76,17 +82,12 @@ describe('validateTextLinks', () => {
).toThrow('Invalid URL: Protocol must be one of: https:, mailto:.');

expect(() =>
validateTextLinks(
`[foo][1]
[1]: http://foo.bar`,
() => false,
),
validateTextLinks('[foo][1]\n\n[1]: http://foo.bar', () => false),
).toThrow('Invalid URL: Protocol must be one of: https:, mailto:.');

expect(() =>
validateTextLinks(
`[foo][1]
[1]: http://foo.bar "foo bar baz"`,
`[foo][1]\n\n[1]: http://foo.bar "foo bar baz"`,
() => false,
),
).toThrow('Invalid URL: Protocol must be one of: https:, mailto:.');
Expand Down
2 changes: 1 addition & 1 deletion packages/snaps-utils/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ALLOWED_PROTOCOLS = ['https:', 'mailto:'];
* @returns A list of URLs linked to in the string.
*/
function getMarkdownLinks(text: string) {
const tokens = lexer(text);
const tokens = lexer(text, { gfm: false });
const links: (Tokens.Link | Tokens.Generic)[] = [];

// Walk the lexed tokens and collect all link tokens
Expand Down

0 comments on commit 6f9ca36

Please sign in to comment.