Commit 92df4d5e authored by Liang Ding's avatar Liang Ding

🎨 分类 URI 必须指定为非中文路径 Fix #68

parent 81649d2a
......@@ -49,7 +49,7 @@ import java.util.Map;
* Category processor.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.0.0.0, Feb 9, 2020
* @version 2.0.0.1, Feb 27, 2020
* @since 2.0.0
*/
@Singleton
......@@ -161,8 +161,7 @@ public class CategoryProcessor {
final Response response = context.getResponse();
try {
String categoryURI = context.pathVar("categoryURI");
categoryURI = URLs.encode(categoryURI);
final String categoryURI = context.pathVar("categoryURI");
final int currentPageNum = Paginator.getPage(context);
LOGGER.log(Level.DEBUG, "Category [URI={}, currentPageNum={}]", categoryURI, currentPageNum);
final JSONObject category = categoryQueryService.getByURI(categoryURI);
......
......@@ -51,7 +51,7 @@ import java.util.Set;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/lzh984294471">lzh984294471</a>
* @version 2.0.0.0, Feb 9, 2020
* @version 2.0.0.1, Feb 27, 2020
* @since 2.0.0
*/
@Singleton
......@@ -230,7 +230,7 @@ public class CategoryConsole {
* {
* "oId": "",
* "categoryTitle": "",
* "categoryURI": "", // optional
* "categoryURI": "",
* "categoryDescription": "", // optional
* "categoryTags": "tag1, tag2" // optional
* }
......@@ -302,11 +302,15 @@ public class CategoryConsole {
return;
}
String uri = requestJSON.optString(Category.CATEGORY_URI, title);
if (StringUtils.isBlank(uri)) {
uri = title;
final String uri = requestJSON.optString(Category.CATEGORY_URI);
if (StringUtils.isBlank(uri) || !uri.equals(URLs.encode(uri))) {
final JSONObject jsonObject = new JSONObject().put(Keys.STATUS_CODE, false);
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("categoryURIMustBeASCIILabel"));
return;
}
uri = URLs.encode(uri);
mayExist = categoryQueryService.getByURI(uri);
if (null != mayExist && !mayExist.optString(Keys.OBJECT_ID).equals(categoryId)) {
final JSONObject jsonObject = new JSONObject().put(Keys.STATUS_CODE, false);
......@@ -361,7 +365,7 @@ public class CategoryConsole {
* <pre>
* {
* "categoryTitle": "",
* "categoryURI": "", // optional
* "categoryURI": "",
* "categoryDescription": "", // optional
* "categoryTags": "tag1, tag2" // optional
* }
......@@ -433,11 +437,14 @@ public class CategoryConsole {
return;
}
String uri = requestJSONObject.optString(Category.CATEGORY_URI, title);
if (StringUtils.isBlank(uri)) {
uri = title;
final String uri = requestJSONObject.optString(Category.CATEGORY_URI);
if (StringUtils.isBlank(uri) || !uri.equals(URLs.encode(uri))) {
final JSONObject jsonObject = new JSONObject().put(Keys.STATUS_CODE, false);
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("categoryURIMustBeASCIILabel"));
return;
}
uri = URLs.encode(uri);
mayExist = categoryQueryService.getByURI(uri);
if (null != mayExist) {
final JSONObject jsonObject = new JSONObject().put(Keys.STATUS_CODE, false);
......
......@@ -18,12 +18,13 @@
#
# Description: Solo language configurations(en_US).
# Version: 2.39.0.0, Jan 25, 2020
# Version: 2.40.0.0, Feb 27, 2020
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
#
categoryURIMustBeASCIILabel=Category URI only must be English char, digit or symbol, for example: programming-life
inlineMathAllowDigitAfterOpenMarkerLabel=Whether inline math formulas allow a starting $ followed by a number
chinesePunctLabel=Chinese punctuation followed by English comma and period are replaced with Chinese corresponding punctuation
fixTermTypoLabel=Fix term typo
......
......@@ -18,12 +18,13 @@
#
# Description: Solo default language configurations(zh_CN).
# Version: 2.39.0.0, Jan 25, 2020
# Version: 2.40.0.0, Feb 27, 2020
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
#
categoryURIMustBeASCIILabel=\u5206\u7C7B URI \u53EA\u80FD\u4F7F\u7528\u82F1\u6587\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u7B26\u53F7\uFF0C\u4F8B\u5982\uFF1Aprogramming-life
inlineMathAllowDigitAfterOpenMarkerLabel=\u5185\u8054\u6570\u5B66\u516C\u5F0F\u662F\u5426\u5141\u8BB8\u8D77\u59CB $ \u540E\u7D27\u8DDF\u6570\u5B57
chinesePunctLabel=\u4E2D\u6587\u540E\u8DDF\u82F1\u6587\u9017\u53F7\u53E5\u53F7\u7B49\u6807\u70B9\u66FF\u6362\u4E3A\u4E2D\u6587\u5BF9\u5E94\u6807\u70B9
fixTermTypoLabel=\u672F\u8BED\u4FEE\u6B63
......
......@@ -32,7 +32,7 @@ import org.testng.annotations.Test;
* {@link CategoryConsole} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.0, Dec 10, 2018
* @version 1.1.0.1, Feb 27, 2020
* @since 2.1.0
*/
@Test(suiteName = "processor")
......@@ -98,6 +98,7 @@ public class CategoryConsoleTestCase extends AbstractTestCase {
JSONObject category = getCategoryQueryService().getByTitle("分类1");
requestJSON.put(Keys.OBJECT_ID, category.optString(Keys.OBJECT_ID));
requestJSON.put(Category.CATEGORY_TITLE, "新的分类1");
requestJSON.put(Category.CATEGORY_URI, "new-cate-1");
request.setJSON(requestJSON);
mockAdminLogin(request);
......
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