@bbn/bbn 2.0.40 → 2.0.42
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.
|
@@ -91,8 +91,13 @@ function partsToPattern(parts, resolved, requestedOpts) {
|
|
|
91
91
|
case 'literal': {
|
|
92
92
|
// Wrap literals in [ ... ] so your parser won't confuse them with tokens
|
|
93
93
|
if (p.value.length) {
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
if (![' ', ',', '/', '-', ':', '.'].includes(p.value)) {
|
|
95
|
+
const v = p.value.replace(/]/g, '\\]');
|
|
96
|
+
pattern += `[${v}]`;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
pattern += p.value;
|
|
100
|
+
}
|
|
96
101
|
}
|
|
97
102
|
break;
|
|
98
103
|
}
|
|
@@ -452,6 +452,26 @@ export default function parse(input, format, locale) {
|
|
|
452
452
|
const applyFns = [];
|
|
453
453
|
let i = 0;
|
|
454
454
|
while (i < fmt.length) {
|
|
455
|
+
// 1) Handle [literal] blocks first
|
|
456
|
+
if (fmt[i] === '[') {
|
|
457
|
+
let j = i + 1;
|
|
458
|
+
let rawLiteral = '';
|
|
459
|
+
while (j < fmt.length && fmt[j] !== ']') {
|
|
460
|
+
rawLiteral += fmt[j];
|
|
461
|
+
j++;
|
|
462
|
+
}
|
|
463
|
+
if (j < fmt.length && fmt[j] === ']') {
|
|
464
|
+
// We found a closing bracket: treat content as literal
|
|
465
|
+
// Undo our earlier escaping of ']' (we used '\]' when building)
|
|
466
|
+
const literal = rawLiteral.replace(/\\]/g, ']');
|
|
467
|
+
pattern += escapeRegex(literal);
|
|
468
|
+
// No capturing group & no applyFn, we just match this text
|
|
469
|
+
i = j + 1;
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
// If there's no closing ']', fall through and treat '[' as normal char
|
|
473
|
+
}
|
|
474
|
+
// 2) Try to match a token at this position
|
|
455
475
|
let matchedToken = null;
|
|
456
476
|
for (const spec of tokensByLength) {
|
|
457
477
|
if (fmt.startsWith(spec.token, i)) {
|
|
@@ -470,6 +490,7 @@ export default function parse(input, format, locale) {
|
|
|
470
490
|
i += matchedToken.token.length;
|
|
471
491
|
}
|
|
472
492
|
else {
|
|
493
|
+
// 3) Plain literal character
|
|
473
494
|
pattern += escapeRegex(fmt[i]);
|
|
474
495
|
i += 1;
|
|
475
496
|
}
|