mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 16:56:14 -04:00
Amended regex pattern for permission string, taken the prefix options from: https://askubuntu.com/tags/files/info
This commit is contained in:
parent
02c3c031f4
commit
273101eb53
2 changed files with 10 additions and 2 deletions
|
@ -279,6 +279,14 @@ describe('chmod-calculator', () => {
|
||||||
describe('validateSymbolicInput', () => {
|
describe('validateSymbolicInput', () => {
|
||||||
describe('validateOrder', () => {
|
describe('validateOrder', () => {
|
||||||
it('should correctly validate the order of permissions', () => {
|
it('should correctly validate the order of permissions', () => {
|
||||||
|
expect(checkSymbolicString('-rwxrwxrwx')).toBe('');
|
||||||
|
expect(checkSymbolicString('drwxrwxrwx')).toBe('');
|
||||||
|
expect(checkSymbolicString('lrwxrwxrwx')).toBe('');
|
||||||
|
expect(checkSymbolicString('brwxrwxrwx')).toBe('');
|
||||||
|
expect(checkSymbolicString('crwxrwxrwx')).toBe('');
|
||||||
|
expect(checkSymbolicString('srwxrwxrwx')).toBe('');
|
||||||
|
expect(checkSymbolicString('prwxrwxrwx')).toBe('');
|
||||||
|
|
||||||
expect(checkSymbolicString('rwxrwxrwx')).toBe('');
|
expect(checkSymbolicString('rwxrwxrwx')).toBe('');
|
||||||
expect(checkSymbolicString('rw-r--r--')).toBe('');
|
expect(checkSymbolicString('rw-r--r--')).toBe('');
|
||||||
expect(checkSymbolicString('r-xr-xr-x')).toBe('');
|
expect(checkSymbolicString('r-xr-xr-x')).toBe('');
|
||||||
|
|
|
@ -74,7 +74,7 @@ function symbolicToOctal(symbolic: string): number {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkSymbolicString(symbolicInput: string): string {
|
function checkSymbolicString(symbolicInput: string): string {
|
||||||
const generalPattern = /^([d-]|[lf-])?[rwx-]{9}$/;
|
const permissionsRegex = /^([-dlbcsp])?[rwx-]{9}$/;
|
||||||
|
|
||||||
if (symbolicInput.length === 0) {
|
if (symbolicInput.length === 0) {
|
||||||
return '';
|
return '';
|
||||||
|
@ -82,7 +82,7 @@ function checkSymbolicString(symbolicInput: string): string {
|
||||||
if (symbolicInput.length > 10) {
|
if (symbolicInput.length > 10) {
|
||||||
return 'Invalid length.';
|
return 'Invalid length.';
|
||||||
}
|
}
|
||||||
if (!generalPattern.test(symbolicInput)) {
|
if (!permissionsRegex.test(symbolicInput)) {
|
||||||
return 'Invalid permission pattern.';
|
return 'Invalid permission pattern.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue