Skip to content

Commit 6353abb

Browse files
committed
🐛 Fix b3log#12344
1 parent 113952c commit 6353abb

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/main/java/org/b3log/solo/processor/CommentProcessor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.b3log.solo.processor;
1717

18-
1918
import freemarker.template.Template;
2019
import org.b3log.latke.Keys;
2120
import org.b3log.latke.ioc.inject.Inject;
@@ -48,13 +47,12 @@
4847
import java.util.HashMap;
4948
import java.util.Map;
5049

51-
5250
/**
5351
* Comment processor.
5452
*
5553
* @author <a href="http://88250.b3log.org">Liang Ding</a>
5654
* @author ArmstrongCN
57-
* @version 1.3.2.14, May 21, 2017
55+
* @version 1.3.3.0, Aug 31, 2017
5856
* @since 0.3.1
5957
*/
6058
@RequestProcessor
@@ -295,7 +293,6 @@ public void addArticleComment(final HTTPRequestContext context) throws ServletEx
295293
template.process(dataModel, stringWriter);
296294
stringWriter.close();
297295
String cmtTpl = stringWriter.toString();
298-
cmtTpl = Emotions.convert(cmtTpl);
299296

300297
addResult.put("cmtTpl", cmtTpl);
301298
} catch (final Exception e) {

src/main/java/org/b3log/solo/service/CommentMgmtService.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* Comment management service.
5959
*
6060
* @author <a href="http://88250.b3log.org">Liang Ding</a>
61-
* @version 1.3.2.12, Jul 20, 2017
61+
* @version 1.3.3.0, Aug 31, 2017
6262
* @since 0.3.5
6363
*/
6464
@Service
@@ -355,13 +355,7 @@ public JSONObject checkAddCommentRequest(final JSONObject requestJSONObject) {
355355
commentName = Jsoup.clean(commentName, Whitelist.none());
356356
requestJSONObject.put(Comment.COMMENT_NAME, commentName);
357357

358-
// content Markdown & XSS process
359-
commentContent = Markdowns.toHTML(commentContent);
360-
commentContent = Jsoup.clean(commentContent, Whitelist.relaxed());
361-
362-
// Emoji
363358
commentContent = Emotions.toAliases(commentContent);
364-
365359
requestJSONObject.put(Comment.COMMENT_CONTENT, commentContent);
366360

367361
return ret;
@@ -582,7 +576,10 @@ public JSONObject addArticleComment(final JSONObject requestJSONObject) throws S
582576
ret.put(Common.PERMALINK, article.getString(Article.ARTICLE_PERMALINK));
583577

584578
ret.put(Comment.COMMENT_NAME, commentName);
585-
ret.put(Comment.COMMENT_CONTENT, commentContent);
579+
String cmtContent = Emotions.convert(commentContent);
580+
cmtContent = Markdowns.toHTML(cmtContent);
581+
cmtContent = Jsoup.clean(cmtContent, Whitelist.relaxed());
582+
ret.put(Comment.COMMENT_CONTENT, cmtContent);
586583
ret.put(Comment.COMMENT_URL, commentURL);
587584

588585
if (!Strings.isEmptyOrNull(originalCommentId)) {

src/main/java/org/b3log/solo/service/CommentQueryService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import org.b3log.solo.util.Thumbnails;
4141
import org.json.JSONArray;
4242
import org.json.JSONObject;
43+
import org.jsoup.Jsoup;
44+
import org.jsoup.safety.Whitelist;
4345

4446
import javax.servlet.http.HttpServletRequest;
4547
import java.util.ArrayList;
@@ -50,7 +52,7 @@
5052
* Comment query service.
5153
*
5254
* @author <a href="http://88250.b3log.org">Liang Ding</a>
53-
* @version 1.3.1.9, Jun 15, 2017
55+
* @version 1.3.2.0, Aug 31, 2017
5456
* @since 0.3.5
5557
*/
5658
@Service
@@ -190,6 +192,7 @@ public JSONObject getComments(final JSONObject requestJSONObject) throws Service
190192
String commentContent = comment.optString(Comment.COMMENT_CONTENT);
191193
commentContent = Emotions.convert(commentContent);
192194
commentContent = Markdowns.toHTML(commentContent);
195+
commentContent = Jsoup.clean(commentContent, Whitelist.relaxed());
193196
comment.put(Comment.COMMENT_CONTENT, commentContent);
194197

195198
comment.put(Comment.COMMENT_TIME, ((Date) comment.get(Comment.COMMENT_DATE)).getTime());
@@ -253,6 +256,7 @@ public List<JSONObject> getComments(final String onId) throws ServiceException {
253256
String commentContent = comment.optString(Comment.COMMENT_CONTENT);
254257
commentContent = Emotions.convert(commentContent);
255258
commentContent = Markdowns.toHTML(commentContent);
259+
commentContent = Jsoup.clean(commentContent, Whitelist.relaxed());
256260
comment.put(Comment.COMMENT_CONTENT, commentContent);
257261

258262
ret.add(comment);

0 commit comments

Comments
 (0)