@defra/forms-engine-plugin 4.5.5 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/forms-engine-plugin",
3
- "version": "4.5.5",
3
+ "version": "4.6.0",
4
4
  "description": "Defra forms engine",
5
5
  "type": "module",
6
6
  "files": [
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "license": "SEE LICENSE IN LICENSE",
85
85
  "dependencies": {
86
- "@defra/forms-model": "^3.0.637",
86
+ "@defra/forms-model": "^3.0.644",
87
87
  "@defra/hapi-tracing": "^1.29.0",
88
88
  "@defra/interactive-map": "^0.0.17-alpha",
89
89
  "@elastic/ecs-pino-format": "^1.5.0",
@@ -29,7 +29,7 @@ const helpPanelConfig = {
29
29
  dismissible: true,
30
30
  modal: false
31
31
  },
32
- html: '<p class="govuk-body-s govuk-!-margin-bottom-2">You can add points, shapes or lines to the map.</p><ul class="govuk-list govuk-list--number govuk-body-s"><li>Search for a county, place or postcode</li><li>Use the + and - icons to zoom in and out</li><li>Add a point or click \'Done\' when you have finished drawing a line or shape</li><li>Give the location a name</li></ul>'
32
+ html: '<p class="govuk-body-s govuk-!-margin-bottom-2">You can add points, shapes or lines to the map.</p><ul class="govuk-list govuk-list--number govuk-body-s"><li>Search for a county, place or postcode</li><li>Use the + and - icons to zoom in and out</li><li>Double‑click, or select \'Done\', when you have finished drawing a line or shape</li><li>Give the location a name</li></ul>'
33
33
  }
34
34
 
35
35
  const lineFeatureProperties = {
@@ -1,5 +1,8 @@
1
- import { type EmailAddressFieldComponent } from '@defra/forms-model'
2
- import joi from 'joi'
1
+ import {
2
+ preventUnicodeInEmail,
3
+ type EmailAddressFieldComponent
4
+ } from '@defra/forms-model'
5
+ import joi, { type CustomHelpers } from 'joi'
3
6
 
4
7
  import { FormComponent } from '~/src/server/plugins/engine/components/FormComponent.js'
5
8
  import { messageTemplate } from '~/src/server/plugins/engine/pageControllers/validationOptions.js'
@@ -20,7 +23,15 @@ export class EmailAddressField extends FormComponent {
20
23
 
21
24
  const { options } = def
22
25
 
23
- let formSchema = joi.string().email().trim().label(this.label).required()
26
+ let formSchema = joi
27
+ .string()
28
+ .trim()
29
+ .email()
30
+ .custom((value, helpers: CustomHelpers<string>) =>
31
+ preventUnicodeInEmail(value, helpers)
32
+ )
33
+ .label(this.label)
34
+ .required()
24
35
 
25
36
  if (options.required === false) {
26
37
  formSchema = formSchema.allow('')
@@ -69,7 +80,8 @@ export class EmailAddressField extends FormComponent {
69
80
  return {
70
81
  baseErrors: [
71
82
  { type: 'required', template: messageTemplate.required },
72
- { type: 'format', template: messageTemplate.format }
83
+ { type: 'format', template: messageTemplate.format },
84
+ { type: 'unicode', template: messageTemplate.unicode }
73
85
  ],
74
86
  advancedSettingsErrors: []
75
87
  }
@@ -1,5 +1,4 @@
1
1
  import { ControllerType, getHiddenFields } from '@defra/forms-model'
2
- import { validate as isValidUUID } from 'uuid'
3
2
 
4
3
  import { getCacheService } from '~/src/server/plugins/engine/helpers.js'
5
4
  import {
@@ -16,6 +15,7 @@ import {
16
15
  } from '~/src/server/plugins/engine/types.js'
17
16
  import { type FormQuery } from '~/src/server/routes/types.js'
18
17
  import { type Services } from '~/src/server/types.js'
18
+ import { isValidUUID } from '~/src/server/utils/utils.js'
19
19
 
20
20
  const GUID_LENGTH = 36
21
21
 
@@ -44,6 +44,7 @@ export const messageTemplate: Record<string, JoiExpression> = {
44
44
  'Enter {{lowerFirst(#label)}} in the correct format',
45
45
  opts
46
46
  ) as JoiExpression,
47
+ unicode: '{{#label}} includes invalid characters, for example, long dashes',
47
48
  number: '{{#label}} must be a number',
48
49
  numberPrecision: '{{#label}} must have {{#limit}} or fewer decimal places',
49
50
  numberInteger: '{{#label}} must be a whole number',
@@ -69,6 +70,7 @@ export const messages: LanguageMessagesExt = {
69
70
  'string.empty': messageTemplate.required,
70
71
  'string.max': messageTemplate.max,
71
72
  'string.email': messageTemplate.format,
73
+ 'string.unicode': messageTemplate.unicode,
72
74
  'string.pattern.base': messageTemplate.pattern,
73
75
  'string.maxWords': messageTemplate.maxWords,
74
76
 
@@ -1,4 +1,5 @@
1
1
  import { getTraceId } from '@defra/hapi-tracing'
2
+ import Joi from 'joi'
2
3
 
3
4
  import { config } from '~/src/config/index.js'
4
5
 
@@ -22,3 +23,13 @@ export function applyTraceHeaders(
22
23
 
23
24
  return existingHeaders ? Object.assign(existingHeaders, headers) : headers
24
25
  }
26
+
27
+ /**
28
+ * Validates if a string conforms to the uuid structure
29
+ * @param {string} str
30
+ * @returns
31
+ */
32
+ export function isValidUUID(str) {
33
+ const { error } = Joi.string().uuid().validate(str)
34
+ return error === undefined
35
+ }
@@ -1,7 +1,7 @@
1
1
  import { getTraceId } from '@defra/hapi-tracing'
2
2
 
3
3
  import { config } from '~/src/config/index.js'
4
- import { applyTraceHeaders } from '~/src/server/utils/utils.js'
4
+ import { applyTraceHeaders, isValidUUID } from '~/src/server/utils/utils.js'
5
5
 
6
6
  jest.mock('@defra/hapi-tracing')
7
7
 
@@ -51,4 +51,19 @@ describe('Header helper functions', () => {
51
51
 
52
52
  expect(result).toBe(existingHeaders)
53
53
  })
54
+
55
+ it.each([
56
+ { uuid: '1f457a37-7b99-452e-8324-df9e041abff2', valid: true },
57
+ { uuid: '0c9a2690-9a0c-4a2c-98d7-e9ef95615ac9', valid: true },
58
+ { uuid: 'f223de3b-5ae5-44b2-8cee-ea8439adc335', valid: true },
59
+ { uuid: '82ecc90c-bc47-4ec5-80af-1a9fc1c4c08c', valid: true },
60
+ { uuid: 'd99ff582-ecce-474f-a44b-bc5961d977c5', valid: true },
61
+ { uuid: '7afffc8a-81ab-4aa6-a8f5-ecf6a600a781', valid: true },
62
+ { uuid: '7afffc8a81ab4aa6a8f5ecf6a600a781', valid: true },
63
+ { uuid: '', valid: false },
64
+ { uuid: 'uuid', valid: false },
65
+ { uuid: 'h4f84ef8-b5e1-4544-94aa-1b671d50d8cb', valid: false }
66
+ ])('should validate uuid appropriately %s', ({ uuid, valid }) => {
67
+ expect(isValidUUID(uuid)).toBe(valid)
68
+ })
54
69
  })