RobertDober / earmark_parser

The Markdown to AST part of Earmark.
Apache License 2.0
68 stars 26 forks source link

(not a bug): URLs with tilde in them #121

Closed faried closed 1 year ago

faried commented 1 year ago

I ran across this by accident: I posted a message with a link to http://www.splode.com/~friedman/software/emacs-lisp/src/diacriticalize.el and EarmarkParser 1.4.17 didn't mark it up properly. 1.4.23 fixes it, though the Changelog doesn't mention this particular change in behavior. Is this something that could use a test case?

RobertDober commented 1 year ago

sure could, must have been a side effect, I'll look into it.

Ty for this and have a nice Festive Season

faried commented 1 year ago

I came up with

diff --git a/test/acceptance/ast/links_images/link_test.exs b/test/acceptance/ast/links_images/link_test.exs
index 5a5112e..906cdac 100644
--- a/test/acceptance/ast/links_images/link_test.exs
+++ b/test/acceptance/ast/links_images/link_test.exs
@@ -277,6 +277,15 @@ defmodule Acceptance.Ast.LinkImages.LinkTest do

       assert as_ast(markdown) == {:ok, ast, messages}
     end
+
+    test "tilde in url" do
+      markdown = "http://example.com/~user/micros~1.exe"
+      html     = ~s{<p><a href="http://example.com/~user/micros~1.exe">http://example.com/~user/micros~1.exe</a></p>}
+      ast      = parse_html(html)
+      messages = []
+
+      assert as_ast(markdown) == {:ok, ast, messages}
+    end
   end

   describe "Escapes in text (was regtest #198)" do
RobertDober commented 1 year ago

Looks great I will probably refactor it using the EarmarkParserDsl but I'll gladly merge this code in a PR (becausein the long run I wont to get rid of the Floki dependency)

Thank you very much

RobertDober commented 1 year ago

Ty for reporting this, fixed according to your suggestion