Skip to content

Commit

Permalink
fix: remove duplicated regex from member username (#712)
Browse files Browse the repository at this point in the history
* fix: remove duplicated regex fro member username

* fix: improve tests

* fix: remove warnings
  • Loading branch information
spaenleh authored Nov 22, 2024
1 parent ff411f0 commit fecd5a4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 44 deletions.
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default [

rules: {
semi: ['error', 'always'],
quotes: ['error', 'single'],
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'error',

Expand Down
2 changes: 0 additions & 2 deletions src/cookie/cookie.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ describe('Cookie Util Tests', () => {
});

describe('getLangCookie', () => {
// eslint-disable-next-line quotes
it("get user's lang in cookie", () => {
const getCookieSpy = vi.spyOn(Cookies, 'get');
Cookies.set(CookieKeys.Lang, MOCK_LANG);
Expand All @@ -116,7 +115,6 @@ describe('Cookie Util Tests', () => {
});

describe('setLangCookie', () => {
// eslint-disable-next-line quotes
it("save user's lang in cookie", () => {
const mock = vi.spyOn(Cookies, 'set');
setLangCookie(MOCK_LANG, MOCK_DOMAIN);
Expand Down
46 changes: 8 additions & 38 deletions src/member/constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,14 @@ import { describe, expect, it } from 'vitest';
import { MemberConstants } from './constants.js';

describe('Member constants', () => {
const invalidUsername = '<div>';
// prettier-ignore
const invalidUsername1 = 'user1234%66457657\'';
const invalidUsername2 = ' user\u{001A}';
const invalidUsername3 = '\u{008F}USER';
const validUsername = 'Johnny';
// prettier-ignore
const validUsername1 = 'Jéàn de l\'Avoiné';

it('username forbidden characters regex', () => {
expect(invalidUsername).toMatch(
MemberConstants.USERNAME_FORBIDDEN_CHARS_REGEX,
);
expect(invalidUsername1).toMatch(
MemberConstants.USERNAME_FORBIDDEN_CHARS_REGEX,
);
expect(invalidUsername2).toMatch(
MemberConstants.USERNAME_FORBIDDEN_CHARS_REGEX,
);
expect(invalidUsername3).toMatch(
MemberConstants.USERNAME_FORBIDDEN_CHARS_REGEX,
);

expect(validUsername).not.toMatch(
MemberConstants.USERNAME_FORBIDDEN_CHARS_REGEX,
);
expect(validUsername1).not.toMatch(
MemberConstants.USERNAME_FORBIDDEN_CHARS_REGEX,
);
it.each(['Johnny', "Jéàn de l'Avoiné"])('valid username', (username) => {
expect(username).toMatch(MemberConstants.USERNAME_FORMAT_REGEX);
});

it('username format regex', () => {
expect(invalidUsername).not.toMatch(MemberConstants.USERNAME_FORMAT_REGEX);
expect(invalidUsername1).not.toMatch(MemberConstants.USERNAME_FORMAT_REGEX);
expect(invalidUsername2).not.toMatch(MemberConstants.USERNAME_FORMAT_REGEX);
expect(invalidUsername3).not.toMatch(MemberConstants.USERNAME_FORMAT_REGEX);

expect(validUsername).toMatch(MemberConstants.USERNAME_FORMAT_REGEX);
expect(validUsername1).toMatch(MemberConstants.USERNAME_FORMAT_REGEX);
});
it.each(['<div>', "user1234%66457657'", ' user\u{001A}', '\u{008F}USER'])(
'invalid username',
(username) => {
expect(username).not.toMatch(MemberConstants.USERNAME_FORMAT_REGEX);
},
);
});
2 changes: 0 additions & 2 deletions src/member/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const MemberConstants = {
USERNAME_FORBIDDEN_CHARS_REGEX:
/["<>^%\\\u{0000}-\u{001F}\u{007F}-\u{009F}]+/u,
USERNAME_FORMAT_REGEX: /^[^"<>^%\\\u{0000}-\u{001F}\u{007F}-\u{009F}]+$/u,
};
1 change: 0 additions & 1 deletion src/validation/isEmail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ describe('isEmail', () => {
'Some Name <hans@m端ller.com>',
'Some Name <test|123@m端ller.com>',
'Some Name <[email protected]>',
// eslint-disable-next-line quotes
"'Foo Bar, Esq'<[email protected]>",
'Some Name <[email protected]>',
'Some Middle Name <[email protected]>',
Expand Down

0 comments on commit fecd5a4

Please sign in to comment.