Skip to content

registerEditorComponent: Named capture groups in pattern cause console warning. #6501

@CamilleScholtz

Description

@CamilleScholtz

Describe the bug

Using named capture groups in the registerEditorComponent pattern field causes a warning. I think this is because match[0] doesn't exist? Example of my code and the error:

	CMS.registerEditorComponent({
		id: "image",
		label: "Afbeelding",

		fields: [{
			name: "caption",
			label: "Onderschrift",
			widget: "string",
		},
		{
			name: "license",
			label: "Licentie",
			widget: "string",
			required: false,
		}],

		pattern: /^{{< image\n?(?:\scaption="(?<caption>.+)")\n?(?:\slicense="(?<license>.+)")?\s?>}}/,

		fromBlock: (match) => {
			return {
				caption: match.groups.caption,
				license: match.groups.license,
			};
		},

		toBlock: (obj) => {
			return `{{< image caption="${obj.caption}" >}}`;
		},
	});
Sent invalid data to remark. Plugin: image. Value: {{< image caption="Characters and Caricaturas door William Hogarth.a" >}}. Data: {"caption":"Characters and Caricaturas door William Hogarth.a"}

Applicable Versions:

  • Netlify CMS version: 2.15.72
  • Git provider: Github
  • OS: Alpine Linux
  • Browser version: Safari

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugcode to address defects in shipped code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions