aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorozan yigit <ozan.yigit@gmail.com>2021-11-23 16:09:51 -0500
committerozan yigit <ozan.yigit@gmail.com>2021-11-23 16:09:51 -0500
commitd91c473c7c187079a886fcbc27fc7955da52a8fd (patch)
treea66db48d96fda2c7bcfaabb6900dc02c43ce3262
parentc50ef66d119d87e06a041e5522430265ccdce148 (diff)
downloadone-true-awk-d91c473c7c187079a886fcbc27fc7955da52a8fd.tar.gz
resolve parsing of a slash character within a cclass "/[/]/" without escape
-rw-r--r--lex.c33
-rwxr-xr-xtestdir/T.misc4
2 files changed, 31 insertions, 6 deletions
diff --git a/lex.c b/lex.c
index 9d1ae06..f588602 100644
--- a/lex.c
+++ b/lex.c
@@ -523,11 +523,12 @@ int regexpr(void)
static char *buf = NULL;
static int bufsz = 500;
char *bp;
+ int brackets = 0;
if (buf == NULL && (buf = (char *) malloc(bufsz)) == NULL)
- FATAL("out of space for rex expr");
+ FATAL("out of space for reg expr");
bp = buf;
- for ( ; (c = input()) != '/' && c != 0; ) {
+ for ( ; ((c = input()) != '/' || brackets > 0) && c != 0; ) {
if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, "regexpr"))
FATAL("out of space for reg expr %.10s...", buf);
if (c == '\n') {
@@ -538,6 +539,34 @@ int regexpr(void)
} else if (c == '\\') {
*bp++ = '\\';
*bp++ = input();
+ } else if (c == '[') {
+ *bp++ = c;
+ brackets++;
+ if ((c = input()) == '^') {
+ *bp++ = c;
+ if ((c = input()) == ']') {
+ *bp++ = c;
+ if ((c = input()) == '[')
+ *bp++ = c;
+ else
+ unput(c);
+ } else if (c == '[') {
+ *bp++ = c;
+ } else
+ unput(c);
+ } else if (c == ']') { /* []] is ok */
+ *bp++ = c;
+ if ((c = input()) == '[')
+ *bp++ = c;
+ else
+ unput(c);
+ } else if (brackets == 1 && c == '[') { /* [[] is also ok */
+ *bp++ = c;
+ } else
+ unput(c);
+ } else if (c == ']') {
+ *bp++ = c;
+ brackets--;
} else {
*bp++ = c;
}
diff --git a/testdir/T.misc b/testdir/T.misc
index ad34ab8..f12d459 100755
--- a/testdir/T.misc
+++ b/testdir/T.misc
@@ -164,10 +164,6 @@ $awk 'BEGIN { unireghf() }
function unireghf(hfeed) { hfeed[1] = 0 }'
if test -r core; then echo 1>&2 "BAD: T.misc unireghf dropped core"; fi
-echo x | $awk '/[/]/' 2>foo
-grep 'nonterminated character class' foo >/dev/null || error 'BAD: T.misc nonterminated fails'
-if test -r core; then echo 1>&2 "BAD: T.misc nonterminated dropped core"; fi
-
$awk '
function f() { return 12345 }
BEGIN { printf "<%s>\n", f() }