Re: [Stripes-users] content escaping in JSONBuilder

Subject:   Re: [Stripes-users] content escaping in JSONBuilder (find more)
From:  
Date:   Jan 19, 2006 07:47

Return-Path: <hidden>
Received: from pool-68-239-44-142.bos.east.verizon.net ([68.239.44.142] helo=[10.0.1.2])
 by esc49.midphase.com with esmtpsa (TLSv1:RC4-SHA:128)
 (Exim 4.52)
 id 1EzZCk-00008L-7S
 for hidden; Thu, 19 Jan 2006 06:47:54 -0600
Message-Id: <hidden>
Date: Thu, 19 Jan 2006 07:47:54 -0500
From: Tim Fennell <hidden>
Reply-To: hidden
Sender: hidden
To: hidden
Subject: Re: [Stripes-users] content escaping in JSONBuilder
In-Reply-To: <hidden>
Errors-To: hidden
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Original-To: hidden
Delivered-To: hidden
References: <hidden>
X-Mailer: Apple Mail (2.746.2)
Received-SPF: unknown (socket error)
X-AntiAbuse: Sender Address Domain - tfenne.com
X-Source:
X-Source-Args:
X-Source-Dir:
X-Spam-Score: 1.0 (+)
X-Spam-Report: Spam Filtering performed by sourceforge.net.
 See http://spamassassin.org/tag/ for more details.
 Report problems to http://sf.net/tracker/?func=add&group_id=1&atid=200001
 1.0 FORGED_RCVD_HELO       Received: contains a forged HELO
X-BeenThere: hidden
X-Mailman-Version: 2.0.9-sf.net
Precedence: bulk
List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/stripes-users&gt;,
 <mailto:hidden?subject=unsubscribe>
List-Id: A list for dicussing building applications with Stripes. <stripes-users.lists.sourceforge.net>
List-Post: <mailto:hidden>
List-Help: <mailto:hidden?subject=help>
List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/stripes-users&gt;,
 <mailto:hidden?subject=subscribe>
List-Archive: <http://sourceforge.net/mailarchive/forum.php?forum=stripes-users>
Status:

Thanks Sergey.  I've created a JIRA bug for it and will be sure to  
merge in the change for the next release.
-t

On Jan 19, 2006, at 6:17 AM, Sergey Pariev wrote:

> Hi all.
>
> I noticed some errors while using JSONBuilder recently - namely it
> doesn't escape string values which results in errors thet trying to
> eval() it on the JavaScript side. The following is the changes I've
> made to JSONBuilder to eliminate that issue :
>
> - new method added , quote() :
>
> public static String quote(String string) {
>  if (string == null || string.length() == 0) {
>   return "\"\"";
>  }
>  char         b;
>         char         c = 0;
>  int          i;
>  int          len = string.length();
>  StringBuffer sb = new StringBuffer(len + 4);
>  String       t;
>
>  sb.append('"');
>  for (i = 0; i < len; i += 1) {
>   b = c;
>   c = string.charAt(i);
>   switch (c) {
>    case '\\':
>    case '"':
>     sb.append('\\');
>     sb.append(c);
>     break;
>    case '/':
>     if (b == '<') {
>      sb.append('\\');
>     }
>            sb.append(c);
>     break;
>    case '\b':
>     sb.append("\\b");
>     break;
>    case '\t':
>     sb.append("\\t");
>     break;
>    case '\n':
>     sb.append("\\n");
>     break;
>    case '\f':
>     sb.append("\\f");
>     break;
>    case '\r':
>     sb.append("\\r");
>     break;
>    default:
>     if (c < ' ') {
>     t = "000" + Integer.toHexString(c);
>     sb.append("\\u" + t.substring(t.length() - 4));
>     } else {
>      sb.append(c);
>     }
>    }
>  }
>  sb.append('"');
>  return sb.toString();
> }
>
>  - method getScalarAsString was changed as follows :
>
> public String getScalarAsString(Object in) {
>  Class type = in.getClass();
>  String result = null;
>         if (String.class.isAssignableFrom(type)) {
>   result =  quote((String)in) ;
>  }
>  else if(Date.class.isAssignableFrom(type)) {
>   result = "new Date(" + ((Date) in).getTime() + ")";
>   }
>  else {
>   result = in.toString();
>  }   
>   
>  return result ;
> }
>
>
> HTH, Sergey.
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through  
> log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD  
> SPLUNK!
> http://sel.as-us.falkag.net/sel?
> cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Stripes-users mailing list
> hidden
> https://lists.sourceforge.net/lists/listinfo/stripes-users



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Stripes-users mailing list
hidden
https://lists.sourceforge.net/lists/listinfo/stripes-users