Skip to content

Commit

Permalink
Fixes #824 (#1147)
Browse files Browse the repository at this point in the history
* Fixes #824

* Added test

* Separated tests
  • Loading branch information
jorgerobles authored and glasserc committed Jan 22, 2019
1 parent 2de683e commit 2ccfa7e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions test/validate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2ccfa7e

Please sign in to comment.