Handle punctuation marks and angle bracket in the end of a link
This commit is contained in:
parent
e5a8cf2b08
commit
74afaca73b
3 changed files with 34 additions and 0 deletions
|
@ -5,6 +5,8 @@
|
|||
### Fixed
|
||||
|
||||
- Hashtags followed by HTML tags "a", "code" and "pre" were not detected
|
||||
- Incorrect parsing of HTML links inside HTML tags
|
||||
- Punctuation marks in the end of urls were included in the html links
|
||||
|
||||
## 0.2.0 - 2020-07-21
|
||||
|
||||
|
|
|
@ -193,6 +193,7 @@ defmodule Linkify.Parser do
|
|||
buffer
|
||||
|> String.split("<")
|
||||
|> List.first()
|
||||
|> String.replace(~r/[,.;:)>]$/, "")
|
||||
|> strip_parens()
|
||||
|
||||
if url?(str, opts) do
|
||||
|
|
|
@ -114,6 +114,20 @@ defmodule Linkify.ParserTest do
|
|||
assert parse(text) == expected
|
||||
end
|
||||
|
||||
test "handle angle bracket in the end" do
|
||||
text = "google.com <br>"
|
||||
assert parse(text) == "<a href=\"http://google.com\">google.com</a> <br>"
|
||||
|
||||
text = "google.com<br>"
|
||||
assert parse(text) == "<a href=\"http://google.com\">google.com</a><br>"
|
||||
|
||||
text = "google.com<"
|
||||
assert parse(text) == "<a href=\"http://google.com\">google.com</a><"
|
||||
|
||||
text = "google.com>"
|
||||
assert parse(text) == "<a href=\"http://google.com\">google.com</a>>"
|
||||
end
|
||||
|
||||
test "does not link attributes" do
|
||||
text = "Check out <a href='google.com'>google</a>"
|
||||
assert parse(text) == text
|
||||
|
@ -185,6 +199,23 @@ defmodule Linkify.ParserTest do
|
|||
assert parse(text, class: false, rel: false) == expected
|
||||
end
|
||||
|
||||
test "do not link punctuation marks in the end" do
|
||||
text = "google.com."
|
||||
assert parse(text) == "<a href=\"http://google.com\">google.com</a>."
|
||||
|
||||
text = "google.com;"
|
||||
assert parse(text) == "<a href=\"http://google.com\">google.com</a>;"
|
||||
|
||||
text = "google.com:"
|
||||
assert parse(text) == "<a href=\"http://google.com\">google.com</a>:"
|
||||
|
||||
text = "hack google.com, please"
|
||||
assert parse(text) == "hack <a href=\"http://google.com\">google.com</a>, please"
|
||||
|
||||
text = "(check out google.com)"
|
||||
assert parse(text) == "(check out <a href=\"http://google.com\">google.com</a>)"
|
||||
end
|
||||
|
||||
test "do not link urls" do
|
||||
text = "google.com"
|
||||
assert parse(text, url: false) == text
|
||||
|
|
Loading…
Reference in a new issue