-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add validation for types sign message primary type (#350)
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { stripArrayTypeIfPresent } from './common'; | ||
|
||
describe('CommonUtils', () => { | ||
describe('stripArrayTypeIfPresent', () => { | ||
it('remove array brackets from the type if present', () => { | ||
expect(stripArrayTypeIfPresent('string[]')).toBe('string'); | ||
expect(stripArrayTypeIfPresent('string[5]')).toBe('string'); | ||
}); | ||
|
||
it('return types which are not array without any change', () => { | ||
expect(stripArrayTypeIfPresent('string')).toBe('string'); | ||
expect(stripArrayTypeIfPresent('string []')).toBe('string []'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Function to stripe array brackets if string defining the type has it. | ||
* | ||
* @param typeString - String defining type from which array brackets are required to be removed. | ||
* @returns Parameter string with array brackets [] removed. | ||
*/ | ||
export const stripArrayTypeIfPresent = (typeString: string) => { | ||
if (typeString?.match(/\S\[\d*\]$/u) !== null) { | ||
return typeString.replace(/\[\d*\]$/gu, '').trim(); | ||
} | ||
return typeString; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters