Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field name validation prohibits leading number #7409

Closed
4 tasks done
mtrezza opened this issue May 31, 2021 · 1 comment
Closed
4 tasks done

Field name validation prohibits leading number #7409

mtrezza opened this issue May 31, 2021 · 1 comment

Comments

@mtrezza
Copy link
Member

mtrezza commented May 31, 2021

New Issue Checklist

Issue Description

Parse Server currently prohibits that field name strings start with a number or contain only numbers.

There seems to be no technical reason for this limitation:

  • JavaScript object allows any string as key
  • MongoDB allows any string as key as long as it doesn't interfere with reserves symbols, such as $ or operators such as . in dot notation. Going back as far as MongoDB 2.4 (2016) the restrictions are still the same today:

    Field names cannot contain null characters, dots (.) or dollar signs ($).

  • Parse Server allows - according to docs - any alphanumeric string as key. There seems to be no documented limitation that field names cannot be a string that begins with or only contains numbers.

The validation has been added in Parse Server 2.0.8, which was one of the WIP releases to open source parse server, so it has been there "from the beginning", but it is unclear today why:

d934f3a#diff-b8769df8db7b0a496c0f6bb5478693ae3b54bd5c0e6db957e3b47de558646777R68-R70

Steps to reproduce

Add field name (or class name) with leading number, e.g. "1field".

Actual Outcome

Adding the field fails validation.

Expected Outcome

Adding the field should pass validation.

Failing Test Case / Pull Request

(none)

Environment

Server

  • Parse Server version: 4.5.0
  • Operating system: irrelevant
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): irrelevant

Database

  • System (MongoDB or Postgres): irrelevant
  • Database version: irrelevant
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): irrelevant

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): irrelevant
  • SDK version: irrelevant

Logs

(none)

@mtrezza
Copy link
Member Author

mtrezza commented May 31, 2021

After looking deeper into this, I assume that the restriction is based on historic (non-MongoDB DBMS) restrictions, where SQL parsers are optimized to expect identifiers with a leading latin letter and the QL would for example require quoting to differentiate identifiers from numeric values when omitting quotation:

For example in PostgreSQL:

SELECT 123abc is interpreted as SELECT 123 AS abc.

The SQL docs describe the complexity of quotation requirements:

Identifiers may begin with a digit but unless quoted may not consist solely of digits.

From that I assume that this limitation may not be necessary for the typical Parse Server architecture using MongoDB. However, it may be reflected in how the Parse Server PostgreSQL DB adapter parses and constructs queries and possibly for other non-public or experimental Parse Server DB adapters. Due to this complexity and for compatibility reasons, I suggest to keep this limitation in place and close this issue.

@mtrezza mtrezza closed this as completed May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant