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.

Commit0d43e6a

Browse files
committed
refactor(editor): adjust xss test && clean up
1 parente8d940e commit0d43e6a

File tree

4 files changed

+46
-25
lines changed

4 files changed

+46
-25
lines changed

‎lib/helper/converter/editor_to_html/index.ex‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,5 @@ defmodule Helper.Converter.EditorToHTML do
131131
"<div class=\"#{@clazz.unknow_block}\">[unknow block]</div>"
132132
end
133133

134-
defpinvalid_hint(part,message)do
135-
"<div class=\"#{@clazz.invalid_block}\">[invalid-block]#{part}:#{message}</div>"
136-
end
137-
138134
defstring_to_json(string),do:Jason.decode(string)
139135
end

‎lib/helper/converter/editor_to_html/validator/index.ex‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,6 @@ defmodule Helper.Converter.EditorToHTML.Validator do
6464
validate_with(type,parent_schema,item_schema,data)
6565
end
6666

67-
defpvalidate_block(%{"type"=>"code"})do
68-
# schema = %{text: [:string]}
69-
# case Schema.cast(schema, data) do
70-
# {:error, errors} ->
71-
# format_parse_error("paragraph", errors)
72-
73-
# _ ->
74-
# {:ok, :pass}
75-
# end
76-
{:ok,:pass}
77-
end
78-
7967
defpvalidate_block(%{"type"=>type}),do:raise("undown#{type} block")
8068

8169
defpvalidate_block(e),do:raise("undown block:#{e}")

‎test/helper/converter/editor_to_html_test/index_test.exs‎

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do
22
@moduledocfalse
33

44
useGroupherServerWeb.ConnCase,async:true
5+
6+
aliasHelper.Metric
57
aliasHelper.Converter.EditorToHTML,as:Parser
68

79
# alias Helper.Metric
810
# @clazz Metric.Article.class_names(:html)
911

12+
# "<addr class="cdx-lock">hello</addr> Editor.js <mark class="cdx-marker">workspace</mark>. is an element &lt;script&gt;alert("hello")&lt;/script&gt;"
13+
14+
# "text" : "<script>evil scripts</script>"
15+
@clazzMetric.Article.class_names(:html)
16+
1017
@real_editor_data~S({
1118
"time" : 1567250876713,
1219
"blocks" : [
1320
{
14-
"type" : "code",
21+
"type" : "paragraph",
1522
"data" : {
16-
"lang" : "js",
17-
"text" : "<script>evil scripts</script>"
23+
"text": "content"
1824
}
1925
}
2026
],
@@ -113,12 +119,43 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do
113119
describe"[secure issues]"do
114120
@tag:wip
115121
test"code block should avoid potential xss script attack"do
116-
{:ok,converted}=Parser.to_html(@real_editor_data)
122+
editor_json=%{
123+
"time"=>1_567_250_876_713,
124+
"blocks"=>[
125+
%{
126+
"type"=>"paragraph",
127+
"data"=>%{
128+
"text"=>"<script>evel script</script>"
129+
}
130+
}
131+
],
132+
"version"=>"2.15.0"
133+
}
134+
135+
{:ok,editor_string}=Jason.encode(editor_json)
136+
{:ok,converted}=Parser.to_html(editor_string)
137+
138+
assertconverted==
139+
"<div class=\"#{@clazz.viewer}\"><p>evel script</p><div>"
117140

118-
safe_script=
119-
"<pre><code class=\"lang-js\">&lt;script&gt;evil scripts&lt;/script&gt;</code></pre>"
141+
editor_json=%{
142+
"time"=>1_567_250_876_713,
143+
"blocks"=>[
144+
%{
145+
"type"=>"paragraph",
146+
"data"=>%{
147+
"text"=>"Editor.js is an element &lt;script&gt;evel script&lt;/script&gt;"
148+
}
149+
}
150+
],
151+
"version"=>"2.15.0"
152+
}
153+
154+
{:ok,editor_string}=Jason.encode(editor_json)
155+
{:ok,converted}=Parser.to_html(editor_string)
120156

121-
assertconverted|>String.contains?(safe_script)
157+
assertconverted==
158+
"<div class=\"#{@clazz.viewer}\"><p>Editor.js is an element &lt;script&gt;evel script&lt;/script&gt;</p><div>"
122159
end
123160
end
124161
end

‎test/helper/converter/editor_to_html_test/list_test.exs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do
66
aliasHelper.Metric
77
aliasHelper.Converter.EditorToHTML,as:Parser
88

9-
@clazzMetric.Article.class_names(:html)
9+
#@clazz Metric.Article.class_names(:html)
1010

1111
describe"[list block unit]"do
1212
@editor_json%{
@@ -31,7 +31,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do
3131
],
3232
"version"=>"2.15.0"
3333
}
34-
@tag:wip2
34+
@tag:wip
3535
test"valid list parse should work"do
3636
{:ok,editor_string}=Jason.encode(@editor_json)
3737
# assert {:ok, converted} = Parser.to_html(editor_string)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp