Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/rules/no-reversed-media-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

/**
* Matches reversed link/image syntax like `(text)[url]`, ignoring escaped characters like `\(text\)[url]`.
* The nested group is `\([^()]*\)`, not `\([\s\S]*\)`, so that it cannot overlap the
* The nested group is `\((?:\\[\s\S]|[^()\\])*\)`, not `\([\s\S]*\)`, so that it cannot overlap the
* other alternatives. Overlapping alternatives cause catastrophic backtracking.
*/
const reversedPattern =
/(?<=(?<!\\)(?:\\{2})*)\((?<label>(?:\\.|[^()\\]|\([^()]*\))*)\)\[(?<url>(?:\\.|[^\]\\\r\n])*)\](?!\()/gu;
/(?<=(?<!\\)(?:\\{2})*)\((?<label>(?:\\.|[^()\\]|\((?:\\[\s\S]|[^()\\])*\))*)\)\[(?<url>(?:\\.|[^\]\\\r\n])*)\](?!\()/gu;

//-----------------------------------------------------------------------------
// Rule Definition
Expand Down
131 changes: 131 additions & 0 deletions tests/rules/no-reversed-media-syntax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,137 @@ ruleTester.run("no-reversed-media-syntax", rule, {
},
],
},
// Nested parentheses with escaped characters
{
code: "(a (b \\(c\\)) d)[x]",
output: "[a (b \\(c\\)) d](x)",
errors: [
{
messageId: "reversedSyntax",
line: 1,
column: 1,
endLine: 1,
endColumn: 19,
},
],
},
{
code: "!(a (b \\(c\\)) d)[x]",
output: "![a (b \\(c\\)) d](x)",
errors: [
{
messageId: "reversedSyntax",
line: 1,
column: 2,
endLine: 1,
endColumn: 20,
},
],
},
{
code: "(a (b\\( c))[x]",
output: "[a (b\\( c)](x)",
errors: [
{
messageId: "reversedSyntax",
line: 1,
column: 1,
endLine: 1,
endColumn: 15,
},
],
},
{
code: "!(a (b\\( c))[x]",
output: "![a (b\\( c)](x)",
errors: [
{
messageId: "reversedSyntax",
line: 1,
column: 2,
endLine: 1,
endColumn: 16,
},
],
},
{
code: "(a (b\\) c))[x]",
output: "[a (b\\) c)](x)",
errors: [
{
messageId: "reversedSyntax",
line: 1,
column: 1,
endLine: 1,
endColumn: 15,
},
],
},
{
code: "!(a (b\\) c))[x]",
output: "![a (b\\) c)](x)",
errors: [
{
messageId: "reversedSyntax",
line: 1,
column: 2,
endLine: 1,
endColumn: 16,
},
],
},
{
code: "(a (b\\\\) c)[x]",
output: "[a (b\\\\) c](x)",
errors: [
{
messageId: "reversedSyntax",
line: 1,
column: 1,
endLine: 1,
endColumn: 15,
},
],
},
{
code: "!(a (b\\\\) c)[x]",
output: "![a (b\\\\) c](x)",
errors: [
{
messageId: "reversedSyntax",
line: 1,
column: 2,
endLine: 1,
endColumn: 16,
},
],
},
{
code: "(a (b\\\nc))[x]",
output: "[a (b\\\nc)](x)",
errors: [
{
messageId: "reversedSyntax",
line: 1,
column: 1,
endLine: 2,
endColumn: 7,
},
],
},
{
code: "!(a (b\\\nc))[x]",
output: "![a (b\\\nc)](x)",
errors: [
{
messageId: "reversedSyntax",
line: 1,
column: 2,
endLine: 2,
endColumn: 7,
},
],
},
// Heading
{
code: "# (ESLint)[https://eslint.org/]",
Expand Down
Loading