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 inline code regex mismatch when there is an escaped backtick character inside the backtick #785

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,24 @@ test('Test for backticks with suffix', () => {
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for backticks with an escaped backtick character inside it', () => {
const testString = 'a `;` abc `:` a';
const resultString = 'a <code>;</code> abc <code>:</code> a';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for backticks with an escaped backtick character inside it without prefix and suffix', () => {
const testString = '`#` abc `:`';
const resultString = '<code>#</code> abc <code>:</code>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for backticks with complete escaped backtick characters inside it', () => {
const testString = 'a `&` b `#` c `x` d `6` e `0` f `;` g `test` h';
const resultString = 'a <code>&amp;</code> b <code>#</code> c <code>x</code> d <code>6</code> e <code>0</code> f <code>;</code> g <code>test</code> h';
expect(parser.replace(testString)).toBe(resultString);
});

// Backticks with no content are not replaced with <code>
test('Test for backticks with no content', () => {
const testString = '` `';
Expand Down
4 changes: 2 additions & 2 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export default class ExpensiMark {
// Use the url escaped version of a backtick (`) symbol. Mobile platforms do not support lookbehinds,
// so capture the first and third group and place them in the replacement.
// but we should not replace backtick symbols if they include <pre> tags between them.
regex: /(\B|_|)&#x60;(.*?(?![&#x60;])\S.*?)&#x60;(\B|_|)(?!&#x60;|[^<]*<\/pre>|[^<]*<\/video>)/gm,
replacement: '$1<code>$2</code>$3',
regex: /(\B|_|)&#x60;((?:&#x60;)*)(?!&#x60;)(.*?\S+?.*?)(?<!&#x60;)((?:&#x60;)*)(&#x60;)(\B|_|)(?!&#x60;|[^<]*<\/pre>|[^<]*<\/video>)/gm,
replacement: '$1<code>$2$3$4</code>$6',
},

/**
Expand Down
Loading