Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/server/plugins/engine/components/MultilineTextField.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,51 @@ describe('MultilineTextField', () => {
output: { value: getFormData('') }
}
]
},
{
description: 'Schema max with whitespace replacement',
component: {
title: 'Example textarea',
name: 'myComponent',
type: ComponentType.MultilineTextField,
options: {},
schema: {
max: 10
}
} satisfies MultilineTextFieldComponent,
assertions: [
{
input: getFormData(`h\r\ne\r\nl\r\nl\r\no`),
output: {
value: getFormData(`h\ne\nl\nl\no`)
}
}
]
},
{
description: 'Schema max with whitespace replacement',
component: {
title: 'Example textarea',
name: 'myComponent',
type: ComponentType.MultilineTextField,
options: {},
schema: {
max: 8
}
} satisfies MultilineTextFieldComponent,
assertions: [
{
input: getFormData(`h\r\ne\r\nl\r\nl\r\no`),
output: {
value: getFormData(`h\ne\nl\nl\no`),
errors: [
expect.objectContaining({
text: 'Example textarea must be 8 characters or less'
})
]
}
}
]
}
])('$description', ({ component: def, assertions }) => {
let collection: ComponentCollection
Expand Down
6 changes: 5 additions & 1 deletion src/server/plugins/engine/components/MultilineTextField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@

const { schema, options } = def

let formSchema = Joi.string().trim().label(this.label).required()
let formSchema = Joi.string()
.replace(/\r\n/g, '\n')

Check warning on line 30 in src/server/plugins/engine/components/MultilineTextField.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `String#replaceAll()` over `String#replace()`.

See more on https://sonarcloud.io/project/issues?id=DEFRA_forms-engine-plugin&issues=AZ39yyQDAUIMIUhiHVSr&open=AZ39yyQDAUIMIUhiHVSr&pullRequest=387
.trim()
.label(this.label)
.required()

if (options.required === false) {
formSchema = formSchema.allow('')
Expand Down
Loading