aboutsummaryrefslogtreecommitdiff
path: root/pattern.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-06-07 13:30:25 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-06-07 13:30:25 -0400
commit6d0e4fd1d2bf69b2c36fbda72ebb6b427348318d (patch)
tree5cada2b1137bd95849241e32e3daee692617df36 /pattern.c
parenta8ae09fb8992da08f2ad54d6789773f5e07f704d (diff)
Bugfix: upto patterns should not accept an empty string as a target,
which fixes an issue where `echo "hello@" | bp '{..}{"@"}'` would fail to match properly.
Diffstat (limited to 'pattern.c')
-rw-r--r--pattern.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/pattern.c b/pattern.c
index 2a9767d..a3d66e6 100644
--- a/pattern.c
+++ b/pattern.c
@@ -160,6 +160,9 @@ public bp_pat_t *chain_together(bp_pat_t *first, bp_pat_t *second)
if (first == NULL) return second;
if (second == NULL) return first;
+ if (first->type == BP_STRING && first->max_matchlen == 0) return second;
+ if (second->type == BP_STRING && second->max_matchlen == 0) return first;
+
if (first->type == BP_DEFINITIONS && second->type == BP_DEFINITIONS) {
return Pattern(BP_CHAIN, first->start, second->end, second->min_matchlen, second->max_matchlen, .first=first, .second=second);
}
@@ -244,6 +247,10 @@ static bp_pat_t *_bp_simplepattern(const char *str, const char *end, bool inside
target = NULL;
} else {
target = bp_simplepattern(str, end);
+ // Bugfix: `echo "foo@" | bp '{..}{"@"}'` should be parsed as `.."@"`
+ // not '(.."") "@"'
+ while (target && target->type == BP_STRING && target->max_matchlen == 0)
+ target = bp_simplepattern(target->end, end);
}
return type == BP_UPTO ?
Pattern(BP_UPTO, start, str, 0, -1, .target=target, .skip=extra_arg)