Skip to content

Commit 11c0ac7

Browse files
committed
fix(regex tester): optional groups/captures failing
Fix CorentinTh#1388
1 parent 0b1b98f commit 11c0ac7

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

.eslintrc-auto-import.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@
286286
"watchTriggerable": true,
287287
"watchWithFilter": true,
288288
"whenever": true,
289-
"toValue": true
289+
"toValue": true,
290+
"injectLocal": true,
291+
"provideLocal": true,
292+
"useClipboardItems": true
290293
}
291294
}

auto-imports.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ declare global {
3636
const h: typeof import('vue')['h']
3737
const ignorableWatch: typeof import('@vueuse/core')['ignorableWatch']
3838
const inject: typeof import('vue')['inject']
39+
const injectLocal: typeof import('@vueuse/core')['injectLocal']
3940
const isDefined: typeof import('@vueuse/core')['isDefined']
4041
const isProxy: typeof import('vue')['isProxy']
4142
const isReactive: typeof import('vue')['isReactive']
@@ -65,6 +66,7 @@ declare global {
6566
const onUpdated: typeof import('vue')['onUpdated']
6667
const pausableWatch: typeof import('@vueuse/core')['pausableWatch']
6768
const provide: typeof import('vue')['provide']
69+
const provideLocal: typeof import('@vueuse/core')['provideLocal']
6870
const reactify: typeof import('@vueuse/core')['reactify']
6971
const reactifyObject: typeof import('@vueuse/core')['reactifyObject']
7072
const reactive: typeof import('vue')['reactive']
@@ -128,6 +130,7 @@ declare global {
128130
const useBrowserLocation: typeof import('@vueuse/core')['useBrowserLocation']
129131
const useCached: typeof import('@vueuse/core')['useCached']
130132
const useClipboard: typeof import('@vueuse/core')['useClipboard']
133+
const useClipboardItems: typeof import('@vueuse/core')['useClipboardItems']
131134
const useCloned: typeof import('@vueuse/core')['useCloned']
132135
const useColorMode: typeof import('@vueuse/core')['useColorMode']
133136
const useConfirmDialog: typeof import('@vueuse/core')['useConfirmDialog']
@@ -326,6 +329,7 @@ declare module 'vue' {
326329
readonly h: UnwrapRef<typeof import('vue')['h']>
327330
readonly ignorableWatch: UnwrapRef<typeof import('@vueuse/core')['ignorableWatch']>
328331
readonly inject: UnwrapRef<typeof import('vue')['inject']>
332+
readonly injectLocal: UnwrapRef<typeof import('@vueuse/core')['injectLocal']>
329333
readonly isDefined: UnwrapRef<typeof import('@vueuse/core')['isDefined']>
330334
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
331335
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
@@ -355,6 +359,7 @@ declare module 'vue' {
355359
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
356360
readonly pausableWatch: UnwrapRef<typeof import('@vueuse/core')['pausableWatch']>
357361
readonly provide: UnwrapRef<typeof import('vue')['provide']>
362+
readonly provideLocal: UnwrapRef<typeof import('@vueuse/core')['provideLocal']>
358363
readonly reactify: UnwrapRef<typeof import('@vueuse/core')['reactify']>
359364
readonly reactifyObject: UnwrapRef<typeof import('@vueuse/core')['reactifyObject']>
360365
readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
@@ -418,6 +423,7 @@ declare module 'vue' {
418423
readonly useBrowserLocation: UnwrapRef<typeof import('@vueuse/core')['useBrowserLocation']>
419424
readonly useCached: UnwrapRef<typeof import('@vueuse/core')['useCached']>
420425
readonly useClipboard: UnwrapRef<typeof import('@vueuse/core')['useClipboard']>
426+
readonly useClipboardItems: UnwrapRef<typeof import('@vueuse/core')['useClipboardItems']>
421427
readonly useCloned: UnwrapRef<typeof import('@vueuse/core')['useCloned']>
422428
readonly useColorMode: UnwrapRef<typeof import('@vueuse/core')['useColorMode']>
423429
readonly useConfirmDialog: UnwrapRef<typeof import('@vueuse/core')['useConfirmDialog']>
@@ -610,6 +616,7 @@ declare module '@vue/runtime-core' {
610616
readonly h: UnwrapRef<typeof import('vue')['h']>
611617
readonly ignorableWatch: UnwrapRef<typeof import('@vueuse/core')['ignorableWatch']>
612618
readonly inject: UnwrapRef<typeof import('vue')['inject']>
619+
readonly injectLocal: UnwrapRef<typeof import('@vueuse/core')['injectLocal']>
613620
readonly isDefined: UnwrapRef<typeof import('@vueuse/core')['isDefined']>
614621
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
615622
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
@@ -639,6 +646,7 @@ declare module '@vue/runtime-core' {
639646
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
640647
readonly pausableWatch: UnwrapRef<typeof import('@vueuse/core')['pausableWatch']>
641648
readonly provide: UnwrapRef<typeof import('vue')['provide']>
649+
readonly provideLocal: UnwrapRef<typeof import('@vueuse/core')['provideLocal']>
642650
readonly reactify: UnwrapRef<typeof import('@vueuse/core')['reactify']>
643651
readonly reactifyObject: UnwrapRef<typeof import('@vueuse/core')['reactifyObject']>
644652
readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
@@ -702,6 +710,7 @@ declare module '@vue/runtime-core' {
702710
readonly useBrowserLocation: UnwrapRef<typeof import('@vueuse/core')['useBrowserLocation']>
703711
readonly useCached: UnwrapRef<typeof import('@vueuse/core')['useCached']>
704712
readonly useClipboard: UnwrapRef<typeof import('@vueuse/core')['useClipboard']>
713+
readonly useClipboardItems: UnwrapRef<typeof import('@vueuse/core')['useClipboardItems']>
705714
readonly useCloned: UnwrapRef<typeof import('@vueuse/core')['useCloned']>
706715
readonly useColorMode: UnwrapRef<typeof import('@vueuse/core')['useColorMode']>
707716
readonly useConfirmDialog: UnwrapRef<typeof import('@vueuse/core')['useConfirmDialog']>

src/tools/regex-tester/regex-tester.service.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,51 @@ const regexesData = [
9292
},
9393
],
9494
},
95+
{
96+
regex: '\\s([^\\s\\[]+)(?:\\[(\\d+)\\])?:\\s',
97+
text: 'Nov 11 21:03:26 abc2 def.sh[1]: \nNov 11 21:03:26 abc2 def.sh: ',
98+
flags: 'gm',
99+
result: [
100+
{
101+
captures: [
102+
{
103+
end: 27,
104+
name: '1',
105+
start: 21,
106+
value: 'def.sh',
107+
},
108+
{
109+
end: 29,
110+
name: '2',
111+
start: 28,
112+
value: '1',
113+
},
114+
],
115+
groups: [],
116+
index: 20,
117+
value: ' def.sh[1]: ',
118+
},
119+
{
120+
captures: [
121+
{
122+
end: 60,
123+
name: '1',
124+
start: 54,
125+
value: 'def.sh',
126+
},
127+
{
128+
end: -1,
129+
name: '2',
130+
start: -1,
131+
value: undefined,
132+
},
133+
],
134+
groups: [],
135+
index: 53,
136+
value: ' def.sh: ',
137+
},
138+
],
139+
},
95140
];
96141

97142
describe('regex-tester', () => {

src/tools/regex-tester/regex-tester.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,23 @@ export function matchRegex(regex: string, text: string, flags: string) {
3131
const captures: Array<GroupCapture> = [];
3232
Object.entries(match).forEach(([captureName, captureValue]) => {
3333
if (captureName !== '0' && captureName.match(/\d+/)) {
34+
const captureIndices = indices[Number(captureName)] || [-1, -1];
3435
captures.push({
3536
name: captureName,
3637
value: captureValue,
37-
start: indices[Number(captureName)][0],
38-
end: indices[Number(captureName)][1],
38+
start: captureIndices[0],
39+
end: captureIndices[1],
3940
});
4041
}
4142
});
4243
const groups: Array<GroupCapture> = [];
4344
Object.entries(match.groups || {}).forEach(([groupName, groupValue]) => {
45+
const groupIndices = indices.groups[groupName] || [-1, -1];
4446
groups.push({
4547
name: groupName,
4648
value: groupValue,
47-
start: indices.groups[groupName][0],
48-
end: indices.groups[groupName][1],
49+
start: groupIndices[0],
50+
end: groupIndices[1],
4951
});
5052
});
5153
results.push({

0 commit comments

Comments
 (0)