[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possibly incorrect parsing of double doublequotes
From: |
Mårten Wikström |
Subject: |
Re: Possibly incorrect parsing of double doublequotes |
Date: |
Thu, 12 May 2011 00:21:01 +0200 |
2011/5/11 Chet Ramey <chet.ramey@case.edu>:
> On 5/9/11 8:06 PM, Mårten Wikström wrote:
>
>> There are two problems/solutions here. The comment in the code above
>> seems to indicate that the quotes should actually be thrown away as is
>> done in 4.1. But on the other hand, word_list_remove_quoted_nulls()
>> seems to indicate it should remove all nulls, not just the first.
>> If I fix word_list_remove_quoted_nulls() to actually remove all
>> consecutive nulls, the problem is
>> solved. (At least my simple test-case works). If I revert the line
>> above to the 4.1 version it also
>> solves my problem.
>
> Unfortunately, that will not work. You can't throw away the empty strings
> unless you're sure that you won't be performing word splitting. The best
> example is
>
> f=" val" e=
> echo "$e"$f
>
> which should result in two fields, the first of which is the empty string.
> Bash-4.1 got that wrong.
Oh, I see. Thanks for pointing it out and for the illuminating example.
>>
>> Alas, my understanding of the bash code is fairly limited so my fixes
>> will likely break something. Perhaps someone with a little more
>> insight could tell the right(tm) solution.
>>
>> Anyway, here are the patches.
>> Solution 1, fixing remove_quoted_nulls():
>>
>> *** subst.c 2011-05-10 01:48:54.816322136 +0200
>> --- ../bash-4.2-patched/subst.c 2011-05-10 01:53:31.350806960 +0200
>> *************** remove_quoted_nulls (string)
>> *** 3706,3712 ****
>> break;
>> }
>> else if (string[i] == CTLNUL)
>> ! i++;
>>
>> prev_i = i;
>> ADVANCE_CHAR (string, slen, i);
>> --- 3706,3713 ----
>> break;
>> }
>> else if (string[i] == CTLNUL)
>> ! while (string[i] == CTLNUL)
>> ! i++;
>>
>> prev_i = i;
>> ADVANCE_CHAR (string, slen, i);
>
> It's the right place, but the wrong fix. The code as it reads in bash-4.2
> skips over each character immediately following a CTLNUL. If a sequence
> of CTLNULs appear, it skips every other one. I attached a patch that does
> the right thing.
Ah, you are absolutely right. Thank you for the correction and the patch.
Regards,
Mårten