
Sync 'next' with v0.8.2
@62aab165da5afebdc58879fd810d7c66d6fe6d6a
--- app/utils/Markdown.java
+++ app/utils/Markdown.java
... | ... | @@ -21,6 +21,7 @@ |
21 | 21 |
package utils; |
22 | 22 |
|
23 | 23 |
import models.Project; |
24 |
+import org.apache.commons.lang.StringEscapeUtils; |
|
24 | 25 |
import org.jsoup.Jsoup; |
25 | 26 |
import org.jsoup.nodes.Document; |
26 | 27 |
import org.jsoup.nodes.Element; |
... | ... | @@ -33,10 +34,8 @@ |
33 | 34 |
import java.io.InputStream; |
34 | 35 |
import java.io.InputStreamReader; |
35 | 36 |
import java.io.Reader; |
36 |
-import java.lang.System; |
|
37 | 37 |
import java.net.URI; |
38 | 38 |
import java.net.URISyntaxException; |
39 |
-import java.nio.charset.Charset; |
|
40 | 39 |
|
41 | 40 |
public class Markdown { |
42 | 41 |
|
... | ... | @@ -138,7 +137,7 @@ |
138 | 137 |
"highlight : function(sCode, sLang) { " + |
139 | 138 |
"if(sLang) { try { return hljs.highlight(sLang.toLowerCase(), sCode).value;" + |
140 | 139 |
" } catch(oException) { return sCode; } } }});"); |
141 |
- String rendered = (String) ((Invocable) engine).invokeFunction("marked", source, options); |
|
140 |
+ String rendered = renderByMarked(source, options); |
|
142 | 141 |
rendered = removeJavascriptInHref(rendered); |
143 | 142 |
rendered = checkReferrer(rendered); |
144 | 143 |
return sanitize(rendered); |
... | ... | @@ -147,13 +146,49 @@ |
147 | 146 |
} |
148 | 147 |
} |
149 | 148 |
|
149 |
+ /** |
|
150 |
+ * Renders the source with Marked. |
|
151 |
+ * |
|
152 |
+ * @param source |
|
153 |
+ * @param options |
|
154 |
+ * @return the rendered result or the source if timeout occurs |
|
155 |
+ */ |
|
156 |
+ private static String renderByMarked(@Nonnull String source, Object options) throws InterruptedException { |
|
157 |
+ if (source.isEmpty()) { |
|
158 |
+ return source; |
|
159 |
+ } |
|
160 |
+ |
|
161 |
+ // Try to render and wait at most 5 seconds. |
|
162 |
+ final String[] rendered = new String[1]; |
|
163 |
+ @SuppressWarnings("deprecation") |
|
164 |
+ Thread marked = new Thread() { |
|
165 |
+ @Override |
|
166 |
+ public void run() { |
|
167 |
+ try { |
|
168 |
+ rendered[0] = (String) ((Invocable) engine).invokeFunction( |
|
169 |
+ "marked", source, options); |
|
170 |
+ } catch (Exception e) { |
|
171 |
+ play.Logger.error("[Markdown] Failed to render: " + source, e); |
|
172 |
+ } |
|
173 |
+ } |
|
174 |
+ }; |
|
175 |
+ marked.start(); |
|
176 |
+ marked.join(5000); |
|
177 |
+ |
|
178 |
+ if (rendered[0] == null) { |
|
179 |
+ // This is the only way to stop the script engine. Thread.interrupt does not work. |
|
180 |
+ marked.stop(); |
|
181 |
+ return "<pre>" + StringEscapeUtils.escapeHtml(source) + "</pre>"; |
|
182 |
+ } else { |
|
183 |
+ return rendered[0]; |
|
184 |
+ } |
|
185 |
+ } |
|
186 |
+ |
|
150 | 187 |
public static String render(@Nonnull String source) { |
151 | 188 |
try { |
152 | 189 |
Object options = engine.eval("new Object({gfm: true, tables: true, breaks: true, " + |
153 | 190 |
"pedantic: false, sanitize: false, smartLists: true});"); |
154 |
- String rendered = (String) ((Invocable) engine).invokeFunction("marked", source, |
|
155 |
- options); |
|
156 |
- return sanitize(rendered); |
|
191 |
+ return sanitize(renderByMarked(source, options)); |
|
157 | 192 |
} catch (Exception ex) { |
158 | 193 |
throw new RuntimeException(ex); |
159 | 194 |
} |
+++ docs/ko/relnotes/v0.8.2.txt
... | ... | @@ -0,0 +1,11 @@ |
1 | +Yobi v0.8.2 릴리즈 노트 | |
2 | +======================= | |
3 | + | |
4 | +v0.8.1 이후 버그수정 | |
5 | +-------------------- | |
6 | + | |
7 | +* Jsoup 버그로 인해 마크다운 렌더링 중 에러가 발생하는 문제 (b1d4bb9) | |
8 | +* 메일을 통해 등록된 이슈에 불필요한 빈 줄이 너무 많은 문제 (a5c9992) | |
9 | +* 마크다운 렌더링에 시간이 너무 많이 걸리는 경우, 시스템 전체에 장애를 일으킬 | |
10 | + 수 있는 문제 (ad9b0aa) | |
11 | +* Java8에서 findbugs가 실행되지 않는 문제 (4ada856) |
+++ docs/relnotes/0.8.2.txt
... | ... | @@ -0,0 +1,11 @@ |
1 | +Yobi v0.8.2 Release Notes | |
2 | +========================= | |
3 | + | |
4 | +Fixes since v0.8.1 | |
5 | +------------------ | |
6 | + | |
7 | +* Server error while rendering markdown text because of a Jsoup bug (b1d4bb9) | |
8 | +* Ugly newlines of issues posted by email (a5c9992) | |
9 | +* System might freeze because of markdown text which takes a long time to be | |
10 | + rendered. (ad9b0aa) | |
11 | +* findbugs did not work on Java 8. (4ada856) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?