diff --git a/src/validate.js b/src/validate.js index 222b163287..80d599bd43 100644 --- a/src/validate.js +++ b/src/validate.js @@ -8,7 +8,7 @@ const ajv = new Ajv({ // add custom formats ajv.addFormat( "data-url", - /^data:([a-z]+\/[a-z0-9-+.]+)?;name=(.*);base64,(.*)$/ + /^data:([a-z]+\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/ ); ajv.addFormat( "color", diff --git a/test/validate_test.js b/test/validate_test.js index cb437e894e..072ed61ec2 100644 --- a/test/validate_test.js +++ b/test/validate_test.js @@ -134,6 +134,32 @@ describe("Validation", () => { }); }); + describe("Data-Url validation", () => { + const schema = { + type: "object", + properties: { + dataUrlWithName: { type: "string", format: "data-url" }, + dataUrlWithoutName: { type: "string", format: "data-url" }, + }, + }; + + it("Data-Url with name is accepted", () => { + const formData = { + dataUrlWithName: "data:text/plain;name=file1.txt;base64,x=", + }; + const result = validateFormData(formData, schema); + expect(result.errors).to.have.length.of(0); + }); + + it("Data-Url without name is accepted", () => { + const formData = { + dataUrlWithoutName: "data:text/plain;base64,x=", + }; + const result = validateFormData(formData, schema); + expect(result.errors).to.have.length.of(0); + }); + }); + describe("toErrorList()", () => { it("should convert an errorSchema into a flat list", () => { expect(