File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -87,3 +87,9 @@ export function generalHash(text: string) {
87
87
. digest ( 'hex' ) ;
88
88
return hash ;
89
89
}
90
+
91
+ export function checkEmpty(text: string) {
92
+ const replaced = text . trim ( ) . replace ( / \u3164 / g, '' ) ;
93
+ if ( replaced === '' ) return true ;
94
+ return false ;
95
+ }
Original file line number Diff line number Diff line change 8
8
generateSlugId ,
9
9
escapeForUrl ,
10
10
extractKeys ,
11
+ checkEmpty ,
11
12
} from 'lib/common' ;
12
13
import { diff } from 'json-diff' ;
13
14
import {
@@ -106,6 +107,17 @@ export const updatePost = async (ctx: Context): Promise<*> => {
106
107
meta,
107
108
} : BodySchema = ( ctx . request . body : any ) ;
108
109
110
+ const stringsToCheck = [ title , body , ...tags ] ;
111
+ for ( let i = 0 ; i < stringsToCheck . length ; i ++ ) {
112
+ if ( checkEmpty ( stringsToCheck [ i ] ) ) {
113
+ ctx . status = 400 ;
114
+ ctx . body = {
115
+ name : 'INVALID_TEXT' ,
116
+ } ;
117
+ return ;
118
+ }
119
+ }
120
+
109
121
// validate tags
110
122
if ( tags ) {
111
123
for ( let i = 0 ; i < tags . length ; i ++ ) {
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
10
10
isUUID ,
11
11
formatShortDescription ,
12
12
generalHash ,
13
+ checkEmpty ,
13
14
} from 'lib/common' ;
14
15
import {
15
16
Category ,
@@ -192,6 +193,17 @@ export const writePost = async (ctx: Context): Promise<*> => {
192
193
}
193
194
}
194
195
196
+ const stringsToCheck = [ title , body , ...tags ] ;
197
+ for ( let i = 0 ; i < stringsToCheck . length ; i ++ ) {
198
+ if ( checkEmpty ( stringsToCheck [ i ] ) ) {
199
+ ctx . status = 400 ;
200
+ ctx . body = {
201
+ name : 'INVALID_TEXT' ,
202
+ } ;
203
+ return ;
204
+ }
205
+ }
206
+
195
207
if ( processedSlug === '' || processedSlug . replace ( / \. / g, '' ) === '' ) {
196
208
ctx . status = 400 ;
197
209
ctx . body = {
@@ -283,7 +295,7 @@ export const readPost = async (ctx: Context): Promise<*> => {
283
295
url_slug : urlSlug ,
284
296
fk_user_id : user . id ,
285
297
} ,
286
- order : [ 'created_at' , 'DESC' ] ,
298
+ order : [ [ 'created_at' , 'DESC' ] ] ,
287
299
} ) ;
288
300
if ( ! history ) {
289
301
ctx . status = 404 ;
You can’t perform that action at this time.
0 commit comments