diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-04-04 23:00:49 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-04-04 23:00:49 -0700 |
commit | 0cb57f957f6ea07a8e33173d39716716db455d30 (patch) | |
tree | af84c6baed373c3ebc6ecd245d09088ac4503682 /lib.c | |
parent | 274cb70971d6a2cebcd887350b4b8602b32743d7 (diff) | |
download | txr-0cb57f957f6ea07a8e33173d39716716db455d30.tar.gz txr-0cb57f957f6ea07a8e33173d39716716db455d30.tar.bz2 txr-0cb57f957f6ea07a8e33173d39716716db455d30.zip |
regex: read/print bug: escaped double quote.
Because the regex printer wrongly uses out_str_char (for the
sake of borrowing its semicolon-notation processing) when
a regex prints, all characters that require escaping in a
string literal get escaped, which includes the " character.
Unfortunately the \" sequence which results is rejected
by the regex parser.
* lib.c (out_str_char): Kludge: add extra argument to
distinguish regex use versus string use, and treat the double
quote accordingly.
(out_str_readable): Give 0 arg to new param of out_str_char.
* lib.h (out_str_char): Declaration updated.
* regex.c (print_class_char, print_rec): Pass 1 to new param
of out_str_char.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -10849,7 +10849,7 @@ static val simple_qref_args_p(val args, val pos) } } -void out_str_char(wchar_t ch, val out, int *semi_flag) +void out_str_char(wchar_t ch, val out, int *semi_flag, int regex) { if (*semi_flag && (iswxdigit(ch) || ch == ';')) put_char(chr(';'), out); @@ -10864,9 +10864,14 @@ void out_str_char(wchar_t ch, val out, int *semi_flag) case '\v': put_string(lit("\\v"), out); break; case '\f': put_string(lit("\\f"), out); break; case '\r': put_string(lit("\\r"), out); break; - case '"': put_string(lit("\\\""), out); break; case '\\': put_string(lit("\\\\"), out); break; case 27: put_string(lit("\\e"), out); break; + case '"': + if (regex) + put_char(chr(ch), out); + else + put_string(lit("\\\""), out); + break; default: { val fmt = nil; @@ -10891,7 +10896,7 @@ void out_str_char(wchar_t ch, val out, int *semi_flag) static void out_str_readable(const wchar_t *ptr, val out, int *semi_flag) { for (; *ptr; ptr++) - out_str_char(*ptr, out, semi_flag); + out_str_char(*ptr, out, semi_flag, 0); } static void out_lazy_str(val lstr, val out) |