apostrophecms / apostrophecms/apostrophe
3.0: UI string validation
- Dominant language
- JavaScript
- Stars
- 4.6k
- Forks
- 650
- Avg merge
- 19h 21m
- Merged PRs (30d)
- 23
Description
## Describe the bug
1. The UI is not validating length constraints at all. On submission, the string value is just cut off by the backend API.
2. Interesting enough, providing number for the string field enables the integer validation (compare number values instead string length)
Step by step instructions to reproduce the behavior:
Add a simple string field with length constraints to any piece:
```js
{
fields: {
add: {
label: {
type: 'string',
label: 'Label',
min: 2,
max: 5
}
}
```
In edit/create mode fill with:
1. `a` - no validation
2. `abcdefgh` - no validation
3. `1` - triggers integer validation (1 < 2)
4. `6` - triggers integer validation (6 > 5)
Enter non valid string `abcdefgh` and hit save. If you go back and observe (or just take a look at the backend response). the result is the field is silently cut off to the max allowed string length by the backend, which IMO is a very bad thing.
## Expected behavior
Validate strings via the UI and do not automatically truncate strings on the back-end
## Details
**Version of Node.js:**
v12.21.0
**Server Operating System:**
Ubuntu 20.04.2 LTS
**Additional context:**
Tested on Chrome, Chromium, Brave, Firfeox against latest state of `3.0` branch
Contributor guide
Research direction
Start by reproducing the issue with a string field using min 2 and max 5 in edit/create mode, testing the listed string and number values. Trace the UI submission and backend API response to determine where validation and truncation occur. Done means invalid string lengths are rejected in the UI and strings are not silently truncated by the backend.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100