Skip to content

Commit

Permalink
Fixed Random exp (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmesh-hemaram authored Oct 4, 2024
1 parent c9f33bf commit 1e09dcc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 12 additions & 3 deletions apps/acf-options-page/src/components/data-list.components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
export function DataList() {
const REGEX_RANGE_STRING = '{6,12}';
const REGEX_STRING = '{6}';
const EMAIL_FIRST = `{1, 20}`;
const EMAIL_SECOND = `{3, 15}`;
const EMAIL_THIRD = `{2, 4}`;

return (
<>
Expand Down Expand Up @@ -93,13 +96,19 @@ export function DataList() {
<option value='Clipboard::Paste::trim()'>Clipboard::Paste::trim()</option>
<option value='Clipboard::Paste::trimStart()'>Clipboard::Paste::trimStart()</option>
<option value='Clipboard::Paste::trimEnd()'>Clipboard::Paste::trimEnd()</option>
<option value='<random[.]{6}>'>&lt;random[.]{REGEX_STRING}&gt;</option>
<option value='<random[.]{6,12}>'>&lt;random[.]{REGEX_RANGE_STRING}&gt;</option>
<option value='<random[a-z]{6}>'>&lt;random[a-z]{REGEX_STRING}&gt;</option>
<option value='<random[a-z]{6,12}>'>&lt;random[a-z]{REGEX_RANGE_STRING}&gt;</option>
<option value='<random[A-Z]{6}>'>&lt;random[A-Z]{REGEX_STRING}&gt;</option>
<option value='<random[\d]{6}>'>&lt;random[\d]{REGEX_STRING}&gt;</option>
<option value='<random[\w]{6}>'>&lt;random[\w]{REGEX_STRING}&gt;</option>
<option value='<random[custom-string]{6}>'>&lt;random[custom-string]{REGEX_STRING}&gt;</option>
<option value='<random(hello|world)>'>&lt;random(hello|world)&gt;</option>
<option value='<random(sun|mon|tue|wednes|thurs|fri|satur)day>'>&lt;random(sun|mon|tue|wednes|thurs|fri|satur)day&gt;</option>
<option value='<random[a-z0-9._+-]{1, 20}@[a-z0-9]{3, 15}\.[a-z]{2, 4}>'>
&lt;random[a-z0-9._+-]{EMAIL_FIRST}@[a-z0-9]{EMAIL_SECOND}\.[a-z]{EMAIL_THIRD}&gt;
</option>
<option value='<randomxxx xtreme dragon warrior xxx /i>'>&lt;randomxxx xtreme dragon warrior xxx /i&gt;</option>
<option value='<randomhello+ (world|to you)>'>&lt;randomhello+ (world|to you)&gt;</option>
<option value='<random stuff: .+>'>&lt;random stuff: .+&gt;</option>
<option value='ScrollTo::TopLeft'>ScrollTo::TopLeft</option>
<option value='ScrollTo::TopRight'>ScrollTo::TopRight</option>
<option value='ScrollTo::BottomLeft'>ScrollTo::BottomLeft</option>
Expand Down
7 changes: 4 additions & 3 deletions libs/acf/util/src/lib/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare global {
export const VALUE_MATCHER = {
QUERY_PARAM: /^Query::/i,
API: /^Api::/i,
RANDOM: /<random(.+)>/gi,
RANDOM: /<random(.+?)(\/[a-z]+)?>/gi,
BATCH_REPEAT: /<batchRepeat>/,
ACTION_REPEAT: /<actionRepeat>/,
SESSION_COUNT: /<sessionCount>/,
Expand All @@ -24,8 +24,9 @@ export const VALUE_MATCHER = {

export const Value = (() => {
const getRandomValue = (value: string) =>
value.replace(VALUE_MATCHER.RANDOM, (_, regex) => {
const randexp = new RandExp(regex, 'i');
value.replace(VALUE_MATCHER.RANDOM, (_, regex, flags) => {
flags = flags ? flags.replace(/[^gimsuy]/g, '') : '';
const randexp = new RandExp(regex, flags);
randexp.defaultRange.add(0, 65535);
const result = randexp.gen();
return result;
Expand Down

0 comments on commit 1e09dcc

Please sign in to comment.