@@ -155,6 +155,8 @@ const requiredColumns = Object.freeze({
155
155
_Role : [ 'name' , 'ACL' ] ,
156
156
} ) ;
157
157
158
+ const invalidColumns = [ 'length' ] ;
159
+
158
160
const systemClasses = Object . freeze ( [
159
161
'_User' ,
160
162
'_Installation' ,
@@ -422,18 +424,24 @@ function classNameIsValid(className: string): boolean {
422
424
// Be a join table OR
423
425
joinClassRegex . test ( className ) ||
424
426
// Include only alpha-numeric and underscores, and not start with an underscore or number
425
- fieldNameIsValid ( className )
427
+ fieldNameIsValid ( className , className )
426
428
) ;
427
429
}
428
430
429
431
// Valid fields must be alpha-numeric, and not start with an underscore or number
430
- function fieldNameIsValid ( fieldName : string ) : boolean {
431
- return classAndFieldRegex . test ( fieldName ) ;
432
+ // must not be a reserved key
433
+ function fieldNameIsValid ( fieldName : string , className : string ) : boolean {
434
+ if ( className && className !== '_Hooks' ) {
435
+ if ( fieldName === 'className' ) {
436
+ return false ;
437
+ }
438
+ }
439
+ return classAndFieldRegex . test ( fieldName ) && ! invalidColumns . includes ( fieldName ) ;
432
440
}
433
441
434
442
// Checks that it's not trying to clobber one of the default fields of the class.
435
443
function fieldNameIsValidForClass ( fieldName : string , className : string ) : boolean {
436
- if ( ! fieldNameIsValid ( fieldName ) ) {
444
+ if ( ! fieldNameIsValid ( fieldName , className ) ) {
437
445
return false ;
438
446
}
439
447
if ( defaultColumns . _Default [ fieldName ] ) {
@@ -976,7 +984,7 @@ export default class SchemaController {
976
984
) {
977
985
for ( const fieldName in fields ) {
978
986
if ( existingFieldNames . indexOf ( fieldName ) < 0 ) {
979
- if ( ! fieldNameIsValid ( fieldName ) ) {
987
+ if ( ! fieldNameIsValid ( fieldName , className ) ) {
980
988
return {
981
989
code : Parse . Error . INVALID_KEY_NAME ,
982
990
error : 'invalid field name: ' + fieldName ,
@@ -1060,7 +1068,7 @@ export default class SchemaController {
1060
1068
fieldName = fieldName . split ( '.' ) [ 0 ] ;
1061
1069
type = 'Object' ;
1062
1070
}
1063
- if ( ! fieldNameIsValid ( fieldName ) ) {
1071
+ if ( ! fieldNameIsValid ( fieldName , className ) ) {
1064
1072
throw new Parse . Error ( Parse . Error . INVALID_KEY_NAME , `Invalid field name: ${ fieldName } .` ) ;
1065
1073
}
1066
1074
@@ -1154,7 +1162,7 @@ export default class SchemaController {
1154
1162
}
1155
1163
1156
1164
fieldNames . forEach ( fieldName => {
1157
- if ( ! fieldNameIsValid ( fieldName ) ) {
1165
+ if ( ! fieldNameIsValid ( fieldName , className ) ) {
1158
1166
throw new Parse . Error ( Parse . Error . INVALID_KEY_NAME , `invalid field name: ${ fieldName } ` ) ;
1159
1167
}
1160
1168
//Don't allow deleting the default fields.
0 commit comments