Skip to content

Commit 4518e40

Browse files
authored
Fix linkparser line handling with multiple parenthesis
1 parent a5b1831 commit 4518e40

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ maddy uses [semver versioning](https://semver.org/).
1717
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) Updated google test to v1.16.0.
1818
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) clang-format
1919
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) automatic update dependencies ci
20+
* ![**FIXED**](https://img.shields.io/badge/-FIXED-%23090) `(This is a [link](/ABC/some file) (the URL will include this).)` should not put the later parenthesis into the link url.
2021

2122
## version 1.3.0 2023-08-26
2223

include/maddy/linkparser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class LinkParser : public LineParser
4040
*/
4141
void Parse(std::string& line) override
4242
{
43-
static std::regex re(R"(\[([^\]]*)\]\(([^\]]*)\))");
43+
static std::regex re(R"(\[([^\]]*)\]\(([^)]*)\))");
4444
static std::string replacement = "<a href=\"$2\">$1</a>";
4545

4646
line = std::regex_replace(line, re, replacement);

tests/maddy/test_maddy_linkparser.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ TEST(MADDY_LINKPARSER, ItReplacesMarkdownWithLinks)
3737
ASSERT_EQ(expected, text);
3838
}
3939

40+
TEST(
41+
MADDY_LINKPARSER, ItReplacesMarkdownProperlyEvenWithMultipleParenthesisInLine
42+
)
43+
{
44+
std::string text =
45+
"(This is a [link](/ABC/some file) (the URL will include this).)";
46+
std::string expected =
47+
"(This is a <a href=\"/ABC/some file\">link</a> (the URL will include "
48+
"this).)";
49+
auto linkParser = std::make_shared<maddy::LinkParser>();
50+
51+
linkParser->Parse(text);
52+
53+
ASSERT_EQ(expected, text);
54+
}
55+
4056
// -----------------------------------------------------------------------------
4157

4258
class DISABLED_MADDY_LINKPARSER : public ::testing::Test

tools/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def main():
123123
"""
124124
if len(sys.argv) != 2:
125125
print(
126-
"Usage: python check_clang_format.py <dry_run|format>"
126+
"Usage: python format.py <dry_run|format>"
127127
)
128128
sys.exit(1)
129129
else:

0 commit comments

Comments
 (0)