fix(stiker-ui): add UUID input test batch builder, add peaceful string pattern

main
Tsu-ba-me 2 years ago
parent caa63c4535
commit 4781a5a158
  1. 9
      striker-ui/lib/consts/REG_EXP_PATTERNS.ts
  2. 4
      striker-ui/lib/test_input/buildPeacefulStringTestBatch.tsx
  3. 23
      striker-ui/lib/test_input/buildUUIDTestBatch.tsx
  4. 2
      striker-ui/lib/test_input/index.ts

@ -1,5 +1,6 @@
const alphanumeric = '[a-z0-9]'; const alphanumeric = '[a-z0-9]';
const alphanumericDash = '[a-z0-9-]'; const alphanumericDash = '[a-z0-9-]';
const hex = '[0-9a-f]';
const octet = '(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9]|)[0-9])'; const octet = '(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9]|)[0-9])';
const ipv4 = `(?:${octet}[.]){3}${octet}`; const ipv4 = `(?:${octet}[.]){3}${octet}`;
@ -11,3 +12,11 @@ export const REP_DOMAIN = new RegExp(
export const REP_IPV4 = new RegExp(`^${ipv4}$`); export const REP_IPV4 = new RegExp(`^${ipv4}$`);
export const REP_IPV4_CSV = new RegExp(`^(?:${ipv4}\\s*,\\s*)*${ipv4}$`); export const REP_IPV4_CSV = new RegExp(`^(?:${ipv4}\\s*,\\s*)*${ipv4}$`);
// Peaceful string is temporarily defined as a string without single-quote, double-quote, slash (/), backslash (\\), angle brackets (< >), and curly brackets ({ }).
export const REP_PEACEFUL_STRING = /^[^'"/\\><}{]+$/;
export const REP_UUID = new RegExp(
`^${hex}{8}-${hex}{4}-[1-5]${hex}{3}-[89ab]${hex}{3}-${hex}{12}$`,
'i',
);

@ -1,3 +1,5 @@
import { REP_PEACEFUL_STRING } from '../consts/REG_EXP_PATTERNS';
import testNotBlank from './testNotBlank'; import testNotBlank from './testNotBlank';
import { InlineMonoText } from '../../components/Text'; import { InlineMonoText } from '../../components/Text';
@ -25,7 +27,7 @@ const buildPeacefulStringTestBatch: BuildInputTestBatchFunction = (
...args, ...args,
); );
}, },
test: ({ value }) => !/['"/\\><}{]/g.test(value as string), test: ({ value }) => REP_PEACEFUL_STRING.test(value as string),
}, },
{ test: testNotBlank }, { test: testNotBlank },
], ],

@ -0,0 +1,23 @@
import { REP_UUID } from '../consts/REG_EXP_PATTERNS';
import testNotBlank from './testNotBlank';
const buildUUIDTestBatch: BuildInputTestBatchFunction = (
inputName,
onSuccess,
{ getValue } = {},
onUUIDTestFailure,
) => ({
defaults: { getValue, onSuccess },
tests: [
{
onFailure: (...args) => {
onUUIDTestFailure(`${inputName} must be a valid UUID.`, ...args);
},
test: ({ value }) => REP_UUID.test(value as string),
},
{ test: testNotBlank },
],
});
export default buildUUIDTestBatch;

@ -1,6 +1,7 @@
import buildDomainTestBatch from './buildDomainTestBatch'; import buildDomainTestBatch from './buildDomainTestBatch';
import buildIPAddressTestBatch from './buildIPAddressTestBatch'; import buildIPAddressTestBatch from './buildIPAddressTestBatch';
import buildPeacefulStringTestBatch from './buildPeacefulStringTestBatch'; import buildPeacefulStringTestBatch from './buildPeacefulStringTestBatch';
import buildUUIDTestBatch from './buildUUIDTestBatch';
import createTestInputFunction from './createTestInputFunction'; import createTestInputFunction from './createTestInputFunction';
import testInput from './testInput'; import testInput from './testInput';
import testLength from './testLength'; import testLength from './testLength';
@ -12,6 +13,7 @@ export {
buildDomainTestBatch, buildDomainTestBatch,
buildIPAddressTestBatch, buildIPAddressTestBatch,
buildPeacefulStringTestBatch, buildPeacefulStringTestBatch,
buildUUIDTestBatch,
createTestInputFunction, createTestInputFunction,
testInput, testInput,
testLength, testLength,

Loading…
Cancel
Save