You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sebb <se...@gmail.com> on 2008/11/04 16:05:04 UTC

[LANG] StringUtils.unescapeCsv() allows unpaired embedded double-quote

Just happened to notice that StringUtils.unescapeCsv() does not check
that embedded double-quotes occur in pairs.

Should this condition be detected, and if so, what should happen?
Throw an Exception? Return the original string untranslated?
Just document the behaviour?

At present the string <"foo"bar"> is returned as <foo"bar>.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] StringUtils.unescapeCsv() allows unpaired embedded double-quote

Posted by sebb <se...@gmail.com>.
Because the rule is that embedded double-quotes should be doubled.
This is essential when unescaping a CSV list.

For example, suppose one needs to escape the two fields:

abcd","efgh
zyx

This is encoded as

"abcd"",""efgh",xyz

This allows the individual fields to be recovered correctly, as the
unescaper knows that the "" pair is part of the field, not the end of
the field.

If it were

"abcd","efgh",xyz

then the unescaper would see the following fields

abcd
efgh
xyz

If the quoting character (double-quote) is not escaped (by doubling
it) then it's not possible in general to determine what the unescaped
fields should be.

>  -v
>
>
>  On Tue, Nov 4, 2008 at 8:35 PM, sebb <se...@gmail.com> wrote:
>
>  > Just happened to notice that StringUtils.unescapeCsv() does not check
>  > that embedded double-quotes occur in pairs.
>  >
>  > Should this condition be detected, and if so, what should happen?
>  > Throw an Exception? Return the original string untranslated?
>  > Just document the behaviour?
>  >
>  > At present the string <"foo"bar"> is returned as <foo"bar>.
>  >
>
> > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>  > For additional commands, e-mail: dev-help@commons.apache.org
>  >
>  >
>
>
>  --
>  The first right of human is the right of EGO.
>
> --
>  http://www.xperienceexperience.blogspot.com
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [LANG] StringUtils.unescapeCsv() allows unpaired embedded double-quote

Posted by Viraj Turakhia <vi...@gmail.com>.
Just curious, why is this not the right behaviour?


-v

On Tue, Nov 4, 2008 at 8:35 PM, sebb <se...@gmail.com> wrote:

> Just happened to notice that StringUtils.unescapeCsv() does not check
> that embedded double-quotes occur in pairs.
>
> Should this condition be detected, and if so, what should happen?
> Throw an Exception? Return the original string untranslated?
> Just document the behaviour?
>
> At present the string <"foo"bar"> is returned as <foo"bar>.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
The first right of human is the right of EGO.
--
http://www.xperienceexperience.blogspot.com