Skip to content

Commit

Permalink
fix: improve NAME_REGEX to allow dashes (#717)
Browse files Browse the repository at this point in the history
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com>
  • Loading branch information
dependabot[bot] and WikiRik authored Jul 11, 2023
1 parent 3d51e2b commit f2a1678
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const constants = require('../lib/constants');
const { Sequelize, sequelize } = require('../lib/sequelize');
const config = require('../config');

const NAME_REGEX = /^[\p{L}. -']*$/u;
const NAME_REGEX = /^[\p{L}. \-']*$/u;
const USERNAME_REGEX = /^[a-zA-Z0-9._-]*$/;

const User = sequelize.define('user', {
Expand Down
24 changes: 15 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"devDependencies": {
"@commitlint/cli": "^17.6.6",
"@commitlint/config-conventional": "^17.6.6",
"@faker-js/faker": "^7.6.0",
"@faker-js/faker": "^8.0.2",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"conventional-changelog": "^4.0.0",
Expand Down
38 changes: 19 additions & 19 deletions test/scripts/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ const {
const notSet = (field) => typeof field === 'undefined';

exports.generateUser = (options = {}) => {
if (notSet(options.username)) options.username = faker.random.alphaNumeric(16);
if (notSet(options.first_name)) options.first_name = faker.name.firstName();
if (notSet(options.last_name)) options.last_name = faker.name.lastName();
if (notSet(options.username)) options.username = faker.string.alphanumeric(16);
if (notSet(options.first_name)) options.first_name = faker.person.firstName();
if (notSet(options.last_name)) options.last_name = faker.person.lastName();
if (notSet(options.email)) options.email = faker.internet.email();
if (notSet(options.gender)) options.gender = faker.random.alphaNumeric(16);
if (notSet(options.gender)) options.gender = faker.string.alphanumeric(16);
if (notSet(options.phone)) options.phone = faker.phone.number();
if (notSet(options.date_of_birth)) options.date_of_birth = faker.date.past();
if (notSet(options.about_me)) options.about_me = faker.lorem.paragraph();
if (notSet(options.address)) options.address = faker.lorem.paragraph();
if (notSet(options.password)) options.password = faker.random.alphaNumeric(16);
if (notSet(options.password)) options.password = faker.string.alphanumeric(16);
if (notSet(options.mail_confirmed_at)) options.mail_confirmed_at = new Date();
if (notSet(options.primary_email)) options.primary_email = 'personal';

Expand All @@ -42,7 +42,7 @@ exports.createUser = (options = {}) => {
};

exports.generateMailConfirmation = (user, options = {}) => {
if (notSet(options.value)) options.value = faker.random.alphaNumeric(16);
if (notSet(options.value)) options.value = faker.string.alphanumeric(16);
if (notSet(options.expires_at)) options.expires_at = faker.date.future();
if (user) options.user_id = user.id;

Expand All @@ -54,9 +54,9 @@ exports.createMailConfirmation = (user = null, options = {}) => {
};

exports.generateBody = (options = {}) => {
if (notSet(options.name)) options.name = faker.name.firstName();
if (notSet(options.name)) options.name = faker.person.firstName();
if (notSet(options.description)) options.description = faker.lorem.paragraph();
if (notSet(options.code)) options.code = faker.random.alpha(3);
if (notSet(options.code)) options.code = faker.string.alpha(3);
if (notSet(options.email)) options.email = faker.internet.email();
if (notSet(options.phone)) options.phone = faker.phone.number();
if (notSet(options.address)) options.address = faker.lorem.paragraph();
Expand All @@ -70,7 +70,7 @@ exports.createBody = (options = {}) => {
};

exports.generateCircle = (options = {}, circle = null) => {
if (notSet(options.name)) options.name = faker.name.firstName();
if (notSet(options.name)) options.name = faker.person.firstName();
if (notSet(options.description)) options.description = faker.lorem.paragraph();
if (notSet(options.joinable)) options.joinable = true;
if (circle) options.parent_circle_id = circle.id;
Expand All @@ -83,8 +83,8 @@ exports.createCircle = (options = {}, circle = null) => {
};

exports.generateCampaign = (options = {}) => {
if (notSet(options.name)) options.name = faker.random.alphaNumeric(16);
if (notSet(options.url)) options.url = faker.random.alphaNumeric(16);
if (notSet(options.name)) options.name = faker.string.alphanumeric(16);
if (notSet(options.url)) options.url = faker.string.alphanumeric(16);
if (notSet(options.description_short)) options.description_short = faker.lorem.paragraph();
if (notSet(options.description_long)) options.description_long = faker.lorem.paragraph();

Expand All @@ -97,8 +97,8 @@ exports.createCampaign = (options = {}) => {

exports.generatePermission = (options = {}) => {
if (notSet(options.scope)) options.scope = 'global';
if (notSet(options.action)) options.action = faker.random.alphaNumeric(16);
if (notSet(options.object)) options.object = faker.random.alphaNumeric(16);
if (notSet(options.action)) options.action = faker.string.alphanumeric({ length: 16, casing: 'lower' });
if (notSet(options.object)) options.object = faker.string.alphanumeric({ length: 16, casing: 'lower' });
if (notSet(options.description)) options.description = faker.lorem.paragraph();

return options;
Expand All @@ -109,7 +109,7 @@ exports.createPermission = (options = {}) => {
};

exports.generateRefreshToken = (user, options = {}) => {
if (notSet(options.value)) options.value = faker.random.alphaNumeric(16);
if (notSet(options.value)) options.value = faker.string.alphanumeric(16);
if (user) options.user_id = user.id;

return options;
Expand All @@ -120,7 +120,7 @@ exports.createRefreshToken = (user = null, options = {}) => {
};

exports.generateAccessToken = (user, options = {}) => {
if (notSet(options.value)) options.value = faker.random.alphaNumeric(16);
if (notSet(options.value)) options.value = faker.string.alphanumeric(16);
if (notSet(options.expires_at)) options.expires_at = faker.date.future();
if (user) options.user_id = user.id;

Expand All @@ -132,7 +132,7 @@ exports.createAccessToken = (user = null, options = {}) => {
};

exports.generatePasswordReset = (user, options = {}) => {
if (notSet(options.value)) options.value = faker.random.alphaNumeric(16);
if (notSet(options.value)) options.value = faker.string.alphanumeric(16);
if (notSet(options.expires_at)) options.expires_at = faker.date.future();
if (user) options.user_id = user.id;

Expand Down Expand Up @@ -181,14 +181,14 @@ exports.generatePayment = (body, user, options = {}) => {

if (notSet(options.starts)) options.starts = faker.date.past();
if (notSet(options.expires)) options.expires = faker.date.future();
if (notSet(options.amount)) options.amount = faker.datatype.number({ min: 1 });
if (notSet(options.currency)) options.currency = faker.random.alphaNumeric(3);
if (notSet(options.amount)) options.amount = faker.number.int({ min: 1 });
if (notSet(options.currency)) options.currency = faker.string.alphanumeric(3);

return options;
};

exports.generateMailChange = (user, options = {}) => {
if (notSet(options.value)) options.value = faker.random.alphaNumeric(16);
if (notSet(options.value)) options.value = faker.string.alphanumeric(16);
if (notSet(options.expires_at)) options.expires_at = faker.date.future();
if (notSet(options.new_email)) options.new_email = faker.internet.email();
if (user) options.user_id = user.id;
Expand Down

0 comments on commit f2a1678

Please sign in to comment.