Commit c8f5ff6b authored by Liang Ding's avatar Liang Ding

🐛 Fix #12821

parent 3c6e8bf1
...@@ -28,7 +28,7 @@ import java.util.regex.Pattern; ...@@ -28,7 +28,7 @@ import java.util.regex.Pattern;
* This class defines all tag model relevant keys. * This class defines all tag model relevant keys.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.3, Jun 26, 2019 * @version 1.1.0.4, Jul 22, 2019
*/ */
public final class Tag { public final class Tag {
...@@ -63,11 +63,6 @@ public final class Tag { ...@@ -63,11 +63,6 @@ public final class Tag {
*/ */
public static final Pattern TAG_TITLE_PATTERN = Pattern.compile(TAG_TITLE_PATTERN_STR); public static final Pattern TAG_TITLE_PATTERN = Pattern.compile(TAG_TITLE_PATTERN_STR);
/**
* Max tag count.
*/
public static final int MAX_TAG_COUNT = 4;
/** /**
* Max length of a tag. * Max length of a tag.
*/ */
...@@ -81,9 +76,10 @@ public final class Tag { ...@@ -81,9 +76,10 @@ public final class Tag {
* </ul> * </ul>
* *
* @param tagStr the specified tags * @param tagStr the specified tags
* @param maxTagCount the specified max tag count
* @return formatted tags string * @return formatted tags string
*/ */
public static String formatTags(final String tagStr) { public static String formatTags(final String tagStr, final int maxTagCount) {
final String tagStr1 = tagStr.replaceAll("\\s+", "").replaceAll(",", ",").replaceAll("、", ","). final String tagStr1 = tagStr.replaceAll("\\s+", "").replaceAll(",", ",").replaceAll("、", ",").
replaceAll(";", ",").replaceAll(";", ","); replaceAll(";", ",").replaceAll(";", ",");
String[] tagTitles = tagStr1.split(","); String[] tagTitles = tagStr1.split(",");
...@@ -119,7 +115,7 @@ public final class Tag { ...@@ -119,7 +115,7 @@ public final class Tag {
tagsBuilder.append(title).append(","); tagsBuilder.append(title).append(",");
count++; count++;
if (count >= MAX_TAG_COUNT) { if (maxTagCount <= count) {
break; break;
} }
} }
......
...@@ -51,7 +51,7 @@ import java.util.Set; ...@@ -51,7 +51,7 @@ import java.util.Set;
* Category console request processing. * Category console request processing.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.3.4, Mar 29, 2019 * @version 1.1.3.5, Jul 22, 2019
* @since 2.0.0 * @since 2.0.0
*/ */
@RequestProcessor @RequestProcessor
...@@ -254,7 +254,7 @@ public class CategoryConsole { ...@@ -254,7 +254,7 @@ public class CategoryConsole {
try { try {
final JSONObject requestJSON = context.requestJSON(); final JSONObject requestJSON = context.requestJSON();
String tagsStr = requestJSON.optString(Category.CATEGORY_T_TAGS); String tagsStr = requestJSON.optString(Category.CATEGORY_T_TAGS);
tagsStr = Tag.formatTags(tagsStr); tagsStr = Tag.formatTags(tagsStr, 64);
if (StringUtils.isBlank(tagsStr)) { if (StringUtils.isBlank(tagsStr)) {
throw new ServiceException(langPropsService.get("tagsEmptyLabel")); throw new ServiceException(langPropsService.get("tagsEmptyLabel"));
} }
...@@ -386,7 +386,7 @@ public class CategoryConsole { ...@@ -386,7 +386,7 @@ public class CategoryConsole {
try { try {
final JSONObject requestJSONObject = context.requestJSON(); final JSONObject requestJSONObject = context.requestJSON();
String tagsStr = requestJSONObject.optString(Category.CATEGORY_T_TAGS); String tagsStr = requestJSONObject.optString(Category.CATEGORY_T_TAGS);
tagsStr = Tag.formatTags(tagsStr); tagsStr = Tag.formatTags(tagsStr, 64);
if (StringUtils.isBlank(tagsStr)) { if (StringUtils.isBlank(tagsStr)) {
throw new ServiceException(langPropsService.get("tagsEmptyLabel")); throw new ServiceException(langPropsService.get("tagsEmptyLabel"));
} }
......
...@@ -52,7 +52,7 @@ import static org.b3log.solo.model.Article.*; ...@@ -52,7 +52,7 @@ import static org.b3log.solo.model.Article.*;
* Article management service. * Article management service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.1.4, Jun 6, 2019 * @version 1.3.1.5, Jul 22, 2019
* @since 0.3.5 * @since 0.3.5
*/ */
@Service @Service
...@@ -406,7 +406,7 @@ public class ArticleMgmtService { ...@@ -406,7 +406,7 @@ public class ArticleMgmtService {
try { try {
final JSONObject article = requestJSONObject.getJSONObject(ARTICLE); final JSONObject article = requestJSONObject.getJSONObject(ARTICLE);
String tagsString = article.optString(Article.ARTICLE_TAGS_REF); String tagsString = article.optString(Article.ARTICLE_TAGS_REF);
tagsString = Tag.formatTags(tagsString); tagsString = Tag.formatTags(tagsString, 4);
if (StringUtils.isBlank(tagsString)) { if (StringUtils.isBlank(tagsString)) {
tagsString = "待分类"; tagsString = "待分类";
} }
...@@ -514,7 +514,7 @@ public class ArticleMgmtService { ...@@ -514,7 +514,7 @@ public class ArticleMgmtService {
} }
String tagsString = article.optString(Article.ARTICLE_TAGS_REF); String tagsString = article.optString(Article.ARTICLE_TAGS_REF);
tagsString = Tag.formatTags(tagsString); tagsString = Tag.formatTags(tagsString, 4);
if (StringUtils.isBlank(tagsString)) { if (StringUtils.isBlank(tagsString)) {
tagsString = "待分类"; tagsString = "待分类";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment