Commit c8f5ff6b authored by Liang Ding's avatar Liang Ding

🐛 Fix #12821

parent 3c6e8bf1
......@@ -28,7 +28,7 @@ import java.util.regex.Pattern;
* This class defines all tag model relevant keys.
*
* @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 {
......@@ -63,11 +63,6 @@ public final class Tag {
*/
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.
*/
......@@ -80,10 +75,11 @@ public final class Tag {
* <li>Deduplication</li>
* </ul>
*
* @param tagStr the specified tags
* @param tagStr the specified tags
* @param maxTagCount the specified max tag count
* @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("、", ",").
replaceAll(";", ",").replaceAll(";", ",");
String[] tagTitles = tagStr1.split(",");
......@@ -119,7 +115,7 @@ public final class Tag {
tagsBuilder.append(title).append(",");
count++;
if (count >= MAX_TAG_COUNT) {
if (maxTagCount <= count) {
break;
}
}
......
......@@ -51,7 +51,7 @@ import java.util.Set;
* Category console request processing.
*
* @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
*/
@RequestProcessor
......@@ -254,7 +254,7 @@ public class CategoryConsole {
try {
final JSONObject requestJSON = context.requestJSON();
String tagsStr = requestJSON.optString(Category.CATEGORY_T_TAGS);
tagsStr = Tag.formatTags(tagsStr);
tagsStr = Tag.formatTags(tagsStr, 64);
if (StringUtils.isBlank(tagsStr)) {
throw new ServiceException(langPropsService.get("tagsEmptyLabel"));
}
......@@ -386,7 +386,7 @@ public class CategoryConsole {
try {
final JSONObject requestJSONObject = context.requestJSON();
String tagsStr = requestJSONObject.optString(Category.CATEGORY_T_TAGS);
tagsStr = Tag.formatTags(tagsStr);
tagsStr = Tag.formatTags(tagsStr, 64);
if (StringUtils.isBlank(tagsStr)) {
throw new ServiceException(langPropsService.get("tagsEmptyLabel"));
}
......
......@@ -52,7 +52,7 @@ import static org.b3log.solo.model.Article.*;
* Article management service.
*
* @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
*/
@Service
......@@ -406,7 +406,7 @@ public class ArticleMgmtService {
try {
final JSONObject article = requestJSONObject.getJSONObject(ARTICLE);
String tagsString = article.optString(Article.ARTICLE_TAGS_REF);
tagsString = Tag.formatTags(tagsString);
tagsString = Tag.formatTags(tagsString, 4);
if (StringUtils.isBlank(tagsString)) {
tagsString = "待分类";
}
......@@ -514,7 +514,7 @@ public class ArticleMgmtService {
}
String tagsString = article.optString(Article.ARTICLE_TAGS_REF);
tagsString = Tag.formatTags(tagsString);
tagsString = Tag.formatTags(tagsString, 4);
if (StringUtils.isBlank(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