Commit d683c5c2f1 (tr: support octal ranges) broke the previous behaviour that an escaped dash doesn't indicate a range: '[p\-r]' should match 'p', '-' or 'r', not 'p', 'q' or 'r'.
Add a special case to handle this. function old new delta expand 641 657 +16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 16/0) Total: 16 bytes Signed-off-by: Ron Yorston <[email protected]> --- coreutils/tr.c | 5 +++++ testsuite/tr.tests | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/coreutils/tr.c b/coreutils/tr.c index 8d779d8ea..4d9796f80 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c @@ -117,6 +117,11 @@ static unsigned expand(char *arg, char **buffer_p) arg++; z = arg; ac = bb_process_escape_sequence(&z); + if (ac == '\\' && *z == '-') { + /* An escaped dash isn't a range, don't fall through */ + buffer[pos++] = *z; + continue; + } arg = (char *)z; arg--; *arg = ac; diff --git a/testsuite/tr.tests b/testsuite/tr.tests index 5cca299ac..ab198d9f8 100755 --- a/testsuite/tr.tests +++ b/testsuite/tr.tests @@ -15,6 +15,10 @@ testing "tr understands 0-9A-F" \ "tr -cd '[0-9A-F]'" \ "19AF" "" "19AFH\n" +testing "tr does not treat [p\\-r] as a range" \ + "tr '[p\\-r]' '+'" \ + "o+q+s+\n" "" "opqrs-\n" + optional FEATURE_TR_CLASSES testing "tr understands [:xdigit:]" \ "tr -cd '[:xdigit:]'" \ -- 2.50.1 _______________________________________________ busybox mailing list [email protected] https://lists.busybox.net/mailman/listinfo/busybox
