Skip to content

Commit

Permalink
Merge pull request #1019 from openkfw/adapt-api-joi-validation
Browse files Browse the repository at this point in the history
Add all apostrophe types to api string validation
  • Loading branch information
Stezido authored Dec 10, 2021
2 parents a7be553 + e749f83 commit 1d68108
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,16 @@ jobs:
strategy:
matrix:
node-version: [10.x]
project:
[
project: [
frontend,
api,
blockchain,
# blockchain,
provisioning,
e2e-test,
excel-export-service,
email-notification-service,
storage-service,
logging-service
logging-service,
]

defaults:
Expand Down Expand Up @@ -117,7 +116,7 @@ jobs:
excel-export-service,
email-notification-service,
storage-service,
logging-service
logging-service,
]
include:
- project: frontend
Expand Down
9 changes: 9 additions & 0 deletions api/src/lib/joiValidation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ describe("JoiValidation: safe String", () => {
expect(error.message).to.contain("fails to match the required pattern:");
});

it("Accept a string including apostrophes", async () => {
const text = "Test '1234' it`s an \"example\"";

const { value, error } = Joi.validate(text, safeStringSchema);

expect(value).to.equal(text);
expect(error).to.equal(null);
});

it("Accept a safe Id", async () => {
const text = "Test1234";
const controlValue = "Test1234";
Expand Down
2 changes: 1 addition & 1 deletion api/src/lib/joiValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Joi from "joi";
import { isProductionEnvironment } from "../config";

export const safeStringSchema = Joi.string()
.regex(/^([A-Za-zÀ-ÿ0-9-_!?@#$&*,.:/()[\] ]*)$/)
.regex(/^([A-Za-zÀ-ÿ0-9-_!?@#$&*,"`´'.:/()[\] ]*)$/)
.max(250);
export const safeIdSchema = Joi.string()
.regex(/^([A-Za-zÀ-ÿ0-9-_]*)$/)
Expand Down

0 comments on commit 1d68108

Please sign in to comment.