Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commita4e52b8

Browse files
author
mydearxym
committed
refactor: 💡 editor
improve santizer test case
1 parente6d15e3 commita4e52b8

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

‎lib/helper/sanitizer.ex‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ defmodule Helper.Sanitizer do
1616
Meta.allow_tag_with_uri_attributes("a",["href"],["http","https"])
1717
Meta.allow_tag_with_these_attributes("a",["name","title"])
1818

19-
Meta.allow_tag_with_these_attributes("strong",[])
20-
Meta.allow_tag_with_these_attributes("em",[])
21-
Meta.allow_tag_with_these_attributes("p",[])
19+
# Meta.allow_tag_with_these_attributes("strong", [])
20+
# Meta.allow_tag_with_these_attributes("em", [])
21+
Meta.allow_tag_with_these_attributes("b",[])
22+
Meta.allow_tag_with_these_attributes("i",[])
23+
Meta.allow_tag_with_these_attributes("mark",["class"])
24+
Meta.allow_tag_with_these_attributes("code",["class"])
25+
# Meta.allow_tag_with_these_attributes("p", [])
2226

2327
Meta.strip_everything_not_covered()
2428
end

‎mix.lock‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"mime":{:hex,:mime,"1.3.1","30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8",[:mix],[],"hexpm"},
4949
"mimerl":{:hex,:mimerl,"1.2.0","67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3",[:rebar3],[],"hexpm"},
5050
"mix_test_watch":{:hex,:mix_test_watch,"0.9.0","c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375",[:mix],[{:file_system,"~> 0.2.1 or ~> 0.3",[hex::file_system,repo:"hexpm",optional:false]}],"hexpm"},
51-
"mochiweb":{:hex,:mochiweb,"2.18.0","eb55f1db3e6e960fac4e6db4e2db9ec3602cc9f30b86cd1481d56545c3145d2e",[],[],"hexpm"},
51+
"mochiweb":{:hex,:mochiweb,"2.18.0","eb55f1db3e6e960fac4e6db4e2db9ec3602cc9f30b86cd1481d56545c3145d2e",[:rebar3],[],"hexpm"},
5252
"nanoid":{:hex,:nanoid,"2.0.1","7ddfe8f3abf1a559c3b673878efbe4feb2c81a657e3f0533aa28be5885257674",[:mix],[],"hexpm"},
5353
"parse_trans":{:hex,:parse_trans,"3.3.0","09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1",[:rebar3],[],"hexpm"},
5454
"phoenix":{:hex,:phoenix,"1.4.9","746d098e10741c334d88143d3c94cab1756435f94387a63441792e66ec0ee974",[:mix],[{:jason,"~> 1.0",[hex::jason,repo:"hexpm",optional:true]},{:phoenix_pubsub,"~> 1.1",[hex::phoenix_pubsub,repo:"hexpm",optional:false]},{:plug,"~> 1.8.1 or ~> 1.9",[hex::plug,repo:"hexpm",optional:false]},{:plug_cowboy,"~> 1.0 or ~> 2.0",[hex::plug_cowboy,repo:"hexpm",optional:true]},{:telemetry,"~> 0.4",[hex::telemetry,repo:"hexpm",optional:false]}],"hexpm"},

‎test/helper/sanitizer_test.exs‎

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,54 @@ defmodule GroupherServer.Test.Helper.Sanitizer do
44
useGroupherServerWeb.ConnCase,async:true
55

66
aliasHelper.RichTextParser,as:Parser
7+
aliasHelper.Sanitizer
78

89
describe"[snaitizer test]"do
910
@tag:wip
10-
test"basic test"do
11-
html="hello<h1>1</h1><h2>2</h2><h3>3</h3><h4>4</h4><h5>5</h5><h6>6</h6>world"
12-
sanitized=Helper.Sanitizer.sanitize(html)
13-
assertsanitized="hello123456world"
11+
test"should strip p h1-6 etc tags"do
12+
html="<p>hello</p><h1>1</h1><h2>2</h2><h3>3</h3><h4>4</h4><h5>5</h5><h6>6</h6>world"
13+
14+
assertSanitizer.sanitize(html)=="hello123456world"
1415
end
1516

1617
@tag:wip
1718
test"disallow ftp urls"do
18-
html="<p>This is <a href=\"ftp://ftp.google.com/test\">FTP test</a></p>"
19-
sanitized=Helper.Sanitizer.sanitize(html)
20-
assertsanitized=="<p>This is <a>FTP test</a></p>"
19+
html="This is <a href=\"ftp://ftp.google.com/test\">FTP test</a>"
20+
21+
assertSanitizer.sanitize(html)=="This is <a>FTP test</a>"
22+
end
23+
24+
@tag:wip
25+
test"alow <a/> with name and title "do
26+
html=
27+
"This is <a href=\"http://coderplanets.com/post/1\" name=\"name\" title=\"title\" other=\"other\">cps</a>"
28+
29+
assertSanitizer.sanitize(html)==
30+
"This is <a href=\"http://coderplanets.com/post/1\" name=\"name\" title=\"title\">cps</a>"
31+
end
32+
33+
@tag:wip
34+
test"allow mark tag with class attr"do
35+
html="This <p>is</p> <mark class=\"cool-look\" other=\"other\">mark text</mark>"
36+
assertSanitizer.sanitize(html)=="This is <mark class=\"cool-look\">mark text</mark>"
37+
end
38+
39+
@tag:wip
40+
test"allow code tag with class attr"do
41+
html="This <p>is</p> <code class=\"cool-look\" other=\"other\">code string</code>"
42+
assertSanitizer.sanitize(html)=="This is <code class=\"cool-look\">code string</code>"
43+
end
44+
45+
@tag:wip
46+
test"allow b tag with no attr"do
47+
html="This <p>is</p> <b class=\"cool-look\" other=\"other\">text</b>"
48+
assertSanitizer.sanitize(html)=="This is <b>text</b>"
49+
end
50+
51+
@tag:wip
52+
test"allow i tag with no attr"do
53+
html="This <p>is</p> <i class=\"cool-look\" other=\"other\">text</i>"
54+
assertSanitizer.sanitize(html)=="This is <i>text</i>"
2155
end
2256
end
2357
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp