@amritk/helpers 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -64,6 +64,14 @@ export const escapeRegexPattern = (pattern) => {
|
|
|
64
64
|
// An escape pair like `\/` or `\d`: keep exactly as authored.
|
|
65
65
|
return match;
|
|
66
66
|
});
|
|
67
|
+
// The empty pattern is valid JSON Schema (it matches everything), but an empty
|
|
68
|
+
// regex body would emit `//` \u2014 a line comment, not a literal \u2014 and break the
|
|
69
|
+
// generated file. Emit `(?:)` instead, exactly what `new RegExp('').source`
|
|
70
|
+
// yields: an empty non-capturing group that still matches everything.
|
|
71
|
+
if (escaped === '') {
|
|
72
|
+
escapeCache.set(pattern, '(?:)');
|
|
73
|
+
return '(?:)';
|
|
74
|
+
}
|
|
67
75
|
if (escapeCache.size >= ESCAPE_CACHE_LIMIT) {
|
|
68
76
|
// Evict the single oldest entry (Maps iterate in insertion order) instead
|
|
69
77
|
// of clearing wholesale — a corpus slightly over the limit keeps its hot
|
package/package.json
CHANGED
|
@@ -67,6 +67,15 @@ export const escapeRegexPattern = (pattern: string): string => {
|
|
|
67
67
|
return match
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
+
// The empty pattern is valid JSON Schema (it matches everything), but an empty
|
|
71
|
+
// regex body would emit `//` \u2014 a line comment, not a literal \u2014 and break the
|
|
72
|
+
// generated file. Emit `(?:)` instead, exactly what `new RegExp('').source`
|
|
73
|
+
// yields: an empty non-capturing group that still matches everything.
|
|
74
|
+
if (escaped === '') {
|
|
75
|
+
escapeCache.set(pattern, '(?:)')
|
|
76
|
+
return '(?:)'
|
|
77
|
+
}
|
|
78
|
+
|
|
70
79
|
if (escapeCache.size >= ESCAPE_CACHE_LIMIT) {
|
|
71
80
|
// Evict the single oldest entry (Maps iterate in insertion order) instead
|
|
72
81
|
// of clearing wholesale — a corpus slightly over the limit keeps its hot
|