Skip to content

Commit

Permalink
Merge branch 'WalkerMills-uri_decode_server_tags'
Browse files Browse the repository at this point in the history
  • Loading branch information
boydm committed Oct 1, 2018
2 parents 40f42e7 + 29dcc08 commit 9b1beac
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
3 changes: 2 additions & 1 deletion changelist.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## phoenix_markdown Changelist

### 1.0.2
# Decode HTML escape sequences inside server tags.
# Decode HTML escape sequences inside server tags. (thank you WalkerMills)
# Percent-decode server tags in URI's (thank you WalkerMills)

### 1.0.1
# Earmark configuration now accepts a simple map. Better for config files.
Expand Down
5 changes: 4 additions & 1 deletion lib/phoenix_markdown/engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ defmodule PhoenixMarkdown.Engine do
# --------------------------------------------------------
defp do_restore_smart_tags(markdown, true) do
smart_tag = ~r/<%.*?%>/
Regex.replace(smart_tag, markdown, &HtmlEntities.decode/1)
markdown = Regex.replace(smart_tag, markdown, &HtmlEntities.decode/1)

uri_smart_tag = ~r/%3C%25+.*?%25%3E/
Regex.replace(uri_smart_tag, markdown, &URI.decode/1)
end

defp do_restore_smart_tags(markdown, _), do: markdown
Expand Down
45 changes: 45 additions & 0 deletions test/engine_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,51 @@ defmodule PhoenixMarkdown.EngineTest do

end

test "compile a smart template with smart tags turned on with :all and percent-encoded tags" do
Mix.Config.persist(phoenix_markdown: [earmark: %Earmark.Options{}])
Mix.Config.persist(phoenix_markdown: [server_tags: :all])

data =
"test/fixtures/templates/view_test/my_app/page/smart_sample_links.html.md"
|> Engine.compile("smart_sample_links.html")

assert data ==
{:safe,
[
{:|, [],
[
{:__block__, [],
[
{:=, [],
[
{:tmp1, [], Phoenix.HTML.Engine},
[
{:|, [],
[
{:__block__, [],
[
{:=, [],
[
{:tmp2, [], Phoenix.HTML.Engine},
[
{:|, [],
["", "<h2>Smart Enough For Links</h2>\n<p><a href=\""]}
]
]},
"foo",
{:tmp2, [], Phoenix.HTML.Engine}
]},
"\">foo</a>\n<a href=\""
]}
]
]},
[{:|, [], [{:tmp1, [], Phoenix.HTML.Engine}, "bar"]}]
]},
"\">bar</a>\n<a href=\"<% \"baz\" %>\">baz</a>\n<a href=\"\">foobar</a>\nfin</p>\n"
]}
]}
end

# ============================================================================
# smart tags via :only tag

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Smart Enough For Links

[foo](<% "foo" %>)
[bar](<%= "bar" %>)
[baz](<%% "baz" %>)
[foobar](<%# "foobar" %>)
fin

0 comments on commit 9b1beac

Please sign in to comment.