Skip to content

Commit

Permalink
feat: support longer flag names that can contain special chars (#1380)
Browse files Browse the repository at this point in the history
* feat: support longer flag names that can contain special chars

* test: add flag name validate test with flag name that is too long
  • Loading branch information
joseph-sentry authored Jan 9, 2024
1 parent ee2aa28 commit 008480e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/helpers/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function validateURL(url: string): boolean {

export function isValidFlag(flag: string): boolean {
// eslint-disable-next-line no-useless-escape
const mask = /^[\w\.\-]{1,45}$/
const mask = /^[^\'\"]{1,1024}$/
return flag.length === 0 || mask.test(flag)
}

Expand All @@ -25,7 +25,7 @@ export function validateFlags(flags: string[]): void {

if (invalidFlags.length > 0) {
throw new Error(
`Flags must consist only of alphanumeric characters, '_', '-', or '.' and not exceed 45 characters. Received ${flags}`,
`Flags cannot contain the ' or " characters and cannot exceed 1024 characters. Received ${flags}`,
)
}
}
Expand Down
48 changes: 28 additions & 20 deletions test/helpers/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@ describe('Input Validators', () => {
expect(validate.isValidFlag('-moo-foor')).toBe(true)
})

it('Should pass with a long name and special characters', () => {
expect(validate.isValidFlag('uu-thisnameis-ridculouslylong-javascrip-but-thisisareally-longnamethatisgoing-tobe-supported-withmanymanycharacters-andthisflagname-istoolongto-dispaly-intheui1234567891011121314151617181920212222324252627282829201212-thisnameis$%#%&^')).toBe(true)
})

it('Should throw with a name longer than 1024 characters', () => {
expect(validate.isValidFlag('uu-thisnameis-ridculouslylong-javascrip-but-thisisareally-longnamethatisgoing-tobe-supported-withmanymanycharacters-andthisflagname-istoolongto-dispaly-intheui1234567891011121314151617181920212222324252627282829201212-thisnameis$%#%&^uu-thisnameis-ridculouslylong-javascrip-but-thisisareally-longnamethatisgoing-tobe-supported-withmanymanycharacters-andthisflagname-istoolongto-dispaly-intheui1234567891011121314151617181920212222324252627282829201212-thisnameis$%#%&^uu-thisnameis-ridculouslylong-javascrip-but-thisisareally-longnamethatisgoing-tobe-supported-withmanymanycharacters-andthisflagname-istoolongto-dispaly-intheui1234567891011121314151617181920212222324252627282829201212-thisnameis$%#%&^uu-thisnameis-ridculouslylong-javascrip-but-thisisareally-longnamethatisgoing-tobe-supported-withmanymanycharacters-andthisflagname-istoolongto-dispaly-intheui1234567891011121314151617181920212222324252627282829201212-thisnameis$%#%&^uu-thisnameis-ridculouslylong-javascrip-but-thisisareally-longnamethatisgoing-tobe-supported-withmanymanycharacters-andthisflagname-istoolongto-dispaly-intheui1234567891011121314151617181920212222324252627282829201212-thisnameis$%#%&^uu-thisnameis-ridculouslylong-javascrip-but-thisisareally-longnamethatisgoing-tobe-supported-withmanymanycharacters-andthisflagname-istoolongto-dispaly-intheui1234567891011121314151617181920212222324252627282829201212-thisnameis$%#%&^')).toBe(false)
})

it("should throw when they they not match the pattern", () => {
// arrange
const invalidFlagName = "flag/subflag"
const expectedErrorMessage = "Flags must consist only of alphanumeric characters, '_', '-', or '.' and not exceed 45 characters. Received flag/subflag"
const invalidFlagName = "flag'subflag"

const expectedErrorMessage = "Flags cannot contain the ' or \" characters and cannot exceed 1024 characters. Received flag'subflag"
// act
expect(() => validate.validateFlags([invalidFlagName])).toThrowError(expectedErrorMessage)
})
Expand All @@ -73,28 +81,28 @@ describe('Input Validators', () => {
})

describe('checkSlug()', () => {
it('should return true for a slug with a forward slash', () => {
// arrange
const inputSlug = "testOrg/testRepo"
const expectedResult = true
it('should return true for a slug with a forward slash', () => {
// arrange
const inputSlug = "testOrg/testRepo"
const expectedResult = true

// act
const result = validate.checkSlug(inputSlug)
// act
const result = validate.checkSlug(inputSlug)

// assert
expect(result).toEqual(expectedResult)
})
// assert
expect(result).toEqual(expectedResult)
})

it('should return false for a slug without a forward slash', () => {
// arrange
const inputSlug = 'testRepo'
const expectedResult = false
it('should return false for a slug without a forward slash', () => {
// arrange
const inputSlug = 'testRepo'
const expectedResult = false

// act
const result = validate.checkSlug(inputSlug)
// act
const result = validate.checkSlug(inputSlug)

// assert
expect(result).toEqual(expectedResult)
})
// assert
expect(result).toEqual(expectedResult)
})
})
})

0 comments on commit 008480e

Please sign in to comment.