Commit Graph

21 Commits

Author SHA1 Message Date
Denys Vlasenko
83e434d5b5 hush: fix handling of '' in ${var:+ARG}
This wasn't an ash bug in dollar_altvalue9, it was hush bug (and bash!)

function                                             old     new   delta
expand_one_var                                      2236    2254     +18
expand_vars_to_list                                 1097    1103      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 24/0)               Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20 17:36:06 +02:00
Denys Vlasenko
294eb4612c hush: fix word splitting in ${v:+ARG} - dollar_altvalue1 test
ash might be a bit buggy, need to investigate dollar_altvalue9 test

function                                             old     new   delta
expand_one_var                                      1639    2236    +597
expand_variables                                     112     128     +16
expand_vars_to_list                                 1117    1097     -20
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 613/-20)           Total: 593 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-20 16:29:43 +02:00
Denys Vlasenko
b762c784ca hush: improve ${var#...}, ${var:+...} and ${var/.../...} - handle quoting
dollar_altvalue1 test partially fails: word splitting of unquoted ${var:+...}
is not correct

function                                             old     new   delta
encode_then_expand_vararg                              -     443    +443
expand_one_var                                      1599    1610     +11
parse_stream                                        2756    2753      -3
encode_string                                        250     242      -8
setup_heredoc                                        308     298     -10
expand_and_evaluate_arith                            106      96     -10
encode_then_expand_string                            142     126     -16
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/5 up/down: 454/-47)           Total: 407 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-17 14:21:38 +02:00
Denys Vlasenko
34179956f9 hush: fix "$v" expansion in case patterns when v='[a]'
function                                             old     new   delta
run_list                                            1053    1063     +10
setup_redirects                                      311     320      +9
encode_then_expand_string                            135     142      +7
run_pipe                                            1784    1789      +5
expand_assignments                                    81      86      +5
expand_string_to_string                              124     125      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/0 up/down: 37/0)               Total: 37 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-11 13:47:59 +02:00
Denys Vlasenko
f50e14632f ash: parser: Fix parameter expansion inside inner double quotes
Upstream email:

    parser: Fix parameter expansion inside inner double quotes

    The parsing of parameter expansion inside inner double quotes
    breaks because we never look for ENDVAR while innerdq is true.

            echo "${x#"${x+''}"''}

    This patch fixes it by pushing the syntax stack if innerdq is
    true and we enter a new parameter expansion.

    This patch also fixes a corner case where a bad substitution error
    occurs within arithmetic expansion.

    Reported-by: Denys Vlasenko <vda.linux@googlemail.com>
    Fixes: ab1cecb40478 (" parser: Add syntax stack for recursive...")
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
readtoken1                                          2880    2898     +18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 21:00:59 +02:00
Denys Vlasenko
abf755615e hush: fix a backslash-removal bug in case
function                                             old     new   delta
run_list                                            1270    1053    -217

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 17:25:18 +02:00
Denys Vlasenko
216913c290 ash: parser: Add syntax stack for recursive parsing
This closes 10821.

Upstream patch:

    From: Herbert Xu <herbert@gondor.apana.org.au>
    Date: Fri, 9 Mar 2018 00:14:02 +0800
    parser: Add syntax stack for recursive parsing

    Without a stack of syntaxes we cannot correctly these two cases
    together:

            "${a#'$$'}"
            "${a#"${b-'$$'}"}"

    A recursive parser also helps in some other corner cases such
    as nested arithmetic expansion with paratheses.

    This patch adds a syntax stack allocated from the stack using
    alloca.  As a side-effect this allows us to remove the naked
    backslashes for patterns within double-quotes, which means that
    EXP_QPAT also has to go.

    This patch also fixes removes any backslashes that precede right
    braces when they are present within a parameter expansion context,
    and backslashes that precede double quotes within inner double
    quotes inside a parameter expansion in a here-document context.

    The idea of a recursive parser is based on a patch by Harald van
    Dijk.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

var_bash3, var_bash4 and var_bash6 tests are updated
with the output given by bash-4.3.43

With this patch, the following tests now pass for ash:

    dollar_repl_slash_bash2.tests
    squote_in_varexp2.tests
    squote_in_varexp.tests
    var_bash4.tests

function                                             old     new   delta
readtoken1                                          2615    2874    +259
synstack_push                                          -      54     +54
evalvar                                              574     571      -3
rmescapes                                            330     310     -20
subevalvar                                          1279    1258     -21
argstr                                              1146    1107     -39
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/4 up/down: 313/-83)           Total: 230 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-02 13:15:37 +02:00
Denys Vlasenko
73523079a2 ash,hush: new test dollar_repl_slash_bash2.tests
This fails for ash. hush works.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-30 23:25:24 +02:00
Denys Vlasenko
d4802c6243 hush: fix a='a\\'; echo "${a%\\\\}"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-02 20:48:36 +01:00
Denys Vlasenko
55f8133a4f shell: tweak bkslash_in_varexp.tests, add bkslash_in_varexp1.tests
It turns out bkslash_in_varexp.tests was a bash bug :]

ash and hush fail "corrected" bkslash_in_varexp.tests as well,
just not as badly as I thought (hush gets half of the cases right).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-02 18:12:12 +01:00
Denys Vlasenko
744a20d8f9 shell: two new tests, both fail for ash and hush
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-03-02 17:13:22 +01:00
Denys Vlasenko
8de5b9f88b ash : fix double-quoted "\z" handling
function                                             old     new   delta
readtoken1                                          2602    2608      +6

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-13 14:44:11 +01:00
Denys Vlasenko
675d24aeaf ash: add LINENO support
This patch is a backport from dash of the combination of:
    [SHELL] Add preliminary LINENO support
    [VAR] Fix varinit ordering that broke fc
    [SHELL] Improve LINENO support

function                                             old     new   delta
parse_command                                       1604    1677     +73
calcsize                                             156     223     +67
copynode                                             196     258     +62
evalcommand                                         1546    1606     +60
ash_main                                            1046    1103     +57
lookupvar                                             51     106     +55
evalcase                                             269     317     +48
evaltree                                             501     547     +46
evalfor                                              156     200     +44
evalsubshell                                         156     195     +39
raise_error_syntax                                    11      29     +18
varinit_data                                         120     132     +12
evalfun                                              270     280     +10
funcline                                               -       4      +4
cmdtxt                                               569     572      +3
trapcmd                                              306     304      -2
ash_vmsg                                             153     150      -3
startlinno                                             4       -      -4
funcnest                                               4       -      -4
xxreadtoken                                          263     250     -13
readtoken1                                          2645    2602     -43
------------------------------------------------------------------------------
(add/remove: 1/2 grow/shrink: 14/4 up/down: 598/-69)          Total: 529 bytes
   text	   data	    bss	    dec	    hex	filename
 932834	    481	   6864	 940179	  e5893	busybox_old
 933375	    481	   6856	 940712	  e5aa8	busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-27 22:02:05 +01:00
Denys Vlasenko
42ba757d5e ash: improve set -x to quote strings as necessary
Basen on the patch from Martijn Dekker <martijn@inlv.org>

function                                             old     new   delta
evalcommand                                         1161    1302    +141
maybe_single_quote                                     -      60     +60
getoptscmd                                           527     546     +19
readtoken1                                          2819    2823      +4
localcmd                                             366     364      -2
evaltreenr                                           495     479     -16
evaltree                                             495     479     -16
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/3 up/down: 224/-34)           Total: 190 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-21 13:20:14 +02:00
Denys Vlasenko
4142f0187d ash: fix escaping of a few characters (broken by last commits)
Add a testcase which tests all ASCII punctuation escapes.
NB: hush is failing this test!

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-05 22:19:28 +02:00
Denys Vlasenko
fda9fafe27 ash: fix matching of unicode greek letter rho (cf 81) and similar cases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-05 19:10:21 +02:00
Denys Vlasenko
5d6b8729ed hush testsuite: add many tests from ash testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 17:39:31 +02:00
Denys Vlasenko
13f20919b2 ash: fix handling of NULs in $'abc\000def\x00asd'. Closes 9286
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-25 20:54:25 +02:00
Ron Yorston
84ba50c32f ash: bash-compatible $'...' shouldn't expand in double quotes
Bash doesn't expand its $'...' construct in double quotes:

   $ echo "$'a\tb'"
   $'a\tb'

Change BusyBox ash to do the same.  This also fixes a problem with
here documents where BusyBox ash gave an incorrect result for:

   $ cat <<EOF
   > '$'
   > EOF
   '$'

Reported-by: Timo Teras <timo.teras@iki.fi>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-04-15 22:16:46 +02:00
Denys Vlasenko
fd33e17a2b ash: fix obscure case of replacing + globbing + backslashes
function                                             old     new   delta
subevalvar                                          1152    1178     +26
readtoken1                                          3267    3275      +8
redirect                                            1284    1286      +2
expandarg                                            957     958      +1
expdir                                                 4       -      -4
evalcommand                                         1219    1209     -10
expmeta                                              481     469     -12
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 4/2 up/down: 37/-26)             Total: 11 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2010-06-26 22:55:44 +02:00
Denis Vlasenko
ef527f50e6 ash: optional support for $'...\t...\n...' bashism
function                                             old     new   delta
readtoken1                                          2824    3172    +348
static.C_escapes                                       -      18     +18
parse_command                                       1504    1500      -4
SIT                                                   89      83      -6
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 366/-10)           Total: 356 bytes
2008-06-23 01:52:30 +00:00