@@ -155,6 +155,8 @@ const requiredColumns = Object.freeze({
155155 _Role : [ 'name' , 'ACL' ] ,
156156} ) ;
157157
158+ const invalidColumns = [ 'length' ] ;
159+
158160const systemClasses = Object . freeze ( [
159161 '_User' ,
160162 '_Installation' ,
@@ -422,18 +424,24 @@ function classNameIsValid(className: string): boolean {
422424 // Be a join table OR
423425 joinClassRegex . test ( className ) ||
424426 // Include only alpha-numeric and underscores, and not start with an underscore or number
425- fieldNameIsValid ( className )
427+ fieldNameIsValid ( className , className )
426428 ) ;
427429}
428430
429431// 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 ) ;
432440}
433441
434442// Checks that it's not trying to clobber one of the default fields of the class.
435443function fieldNameIsValidForClass ( fieldName : string , className : string ) : boolean {
436- if ( ! fieldNameIsValid ( fieldName ) ) {
444+ if ( ! fieldNameIsValid ( fieldName , className ) ) {
437445 return false ;
438446 }
439447 if ( defaultColumns . _Default [ fieldName ] ) {
@@ -976,7 +984,7 @@ export default class SchemaController {
976984 ) {
977985 for ( const fieldName in fields ) {
978986 if ( existingFieldNames . indexOf ( fieldName ) < 0 ) {
979- if ( ! fieldNameIsValid ( fieldName ) ) {
987+ if ( ! fieldNameIsValid ( fieldName , className ) ) {
980988 return {
981989 code : Parse . Error . INVALID_KEY_NAME ,
982990 error : 'invalid field name: ' + fieldName ,
@@ -1060,7 +1068,7 @@ export default class SchemaController {
10601068 fieldName = fieldName . split ( '.' ) [ 0 ] ;
10611069 type = 'Object' ;
10621070 }
1063- if ( ! fieldNameIsValid ( fieldName ) ) {
1071+ if ( ! fieldNameIsValid ( fieldName , className ) ) {
10641072 throw new Parse . Error ( Parse . Error . INVALID_KEY_NAME , `Invalid field name: ${ fieldName } .` ) ;
10651073 }
10661074
@@ -1154,7 +1162,7 @@ export default class SchemaController {
11541162 }
11551163
11561164 fieldNames . forEach ( fieldName => {
1157- if ( ! fieldNameIsValid ( fieldName ) ) {
1165+ if ( ! fieldNameIsValid ( fieldName , className ) ) {
11581166 throw new Parse . Error ( Parse . Error . INVALID_KEY_NAME , `invalid field name: ${ fieldName } ` ) ;
11591167 }
11601168 //Don't allow deleting the default fields.
0 commit comments