bug 415302

Patch to protect against null input's.

-=david=-

Signed-off-by: David Harrigan <dharrigan@gmail.com>
This commit is contained in:
David Harrigan 2013-08-18 18:26:28 +01:00 committed by Jan Bartel
parent 8951c4c773
commit e351f04002
1 changed files with 18 additions and 12 deletions

View File

@ -334,12 +334,15 @@ public class QuotedStringTokenizer
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** Quote a string into an Appendable. /** Quote a string into an Appendable.
* Only quotes and backslash are escaped. * Only quotes and backslash are escaped.
* @param buffer The Appendable * @param buffer The Appendable
* @param input The String to quote. * @param input The String to quote.
*/ */
public static void quoteOnly(Appendable buffer, String input) public static void quoteOnly(Appendable buffer, String input)
{ {
if(input==null)
return;
try try
{ {
buffer.append('"'); buffer.append('"');
@ -366,6 +369,9 @@ public class QuotedStringTokenizer
*/ */
public static void quote(Appendable buffer, String input) public static void quote(Appendable buffer, String input)
{ {
if(input==null)
return;
try try
{ {
buffer.append('"'); buffer.append('"');
@ -403,14 +409,14 @@ public class QuotedStringTokenizer
} }
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public static String unquoteOnly(String s) public static String unquoteOnly(String s)
{ {
return unquoteOnly(s, false); return unquoteOnly(s, false);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** Unquote a string, NOT converting unicode sequences /** Unquote a string, NOT converting unicode sequences
* @param s The string to unquote. * @param s The string to unquote.
@ -454,15 +460,15 @@ public class QuotedStringTokenizer
} }
} }
return b.toString(); return b.toString();
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public static String unquote(String s) public static String unquote(String s)
{ {
return unquote(s,false); return unquote(s,false);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** Unquote a string. /** Unquote a string.
* @param s The string to unquote. * @param s The string to unquote.
@ -544,8 +550,8 @@ public class QuotedStringTokenizer
return b.toString(); return b.toString();
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** Check that char c (which is preceded by a backslash) is a valid /** Check that char c (which is preceded by a backslash) is a valid
* escape sequence. * escape sequence.
@ -554,8 +560,8 @@ public class QuotedStringTokenizer
*/ */
private static boolean isValidEscaping(char c) private static boolean isValidEscaping(char c)
{ {
return ((c == 'n') || (c == 'r') || (c == 't') || return ((c == 'n') || (c == 'r') || (c == 't') ||
(c == 'f') || (c == 'b') || (c == '\\') || (c == 'f') || (c == 'b') || (c == '\\') ||
(c == '/') || (c == '"') || (c == 'u')); (c == '/') || (c == '"') || (c == 'u'));
} }
@ -564,7 +570,7 @@ public class QuotedStringTokenizer
{ {
return s!=null && s.length()>0 && s.charAt(0)=='"' && s.charAt(s.length()-1)=='"'; return s!=null && s.length()>0 && s.charAt(0)=='"' && s.charAt(s.length()-1)=='"';
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* @return handle double quotes if true * @return handle double quotes if true