decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

registerEditorComponent: Named capture groups in pattern cause console warning.

Open CamilleScholtz opened this issue 3 years ago • 1 comments

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

CamilleScholtz avatar Jun 27 '22 21:06 CamilleScholtz

Hmm maybe this is not the fault of named capture groups but rather something akin to this: https://github.com/netlify/netlify-cms/issues/4895

CamilleScholtz avatar Jun 30 '22 21:06 CamilleScholtz

Closing as duplicate of #4895

martinjagodic avatar Jun 01 '23 11:06 martinjagodic