embedly/jquery-preview — Issue #6: Unnecessary encoding/decoding of input values?
Author: brentc
Created: 2012-02-03 00:15:47+00:00
State: open

I noticed the data is being encoded a number of times before being decoded right before being submitted. As best as I can tell this is completely unnecessary, and it causes at least one issue that I've identified so far.

When the value for obj.safe is encoded it becomes a string "true" or "false", which, when decoded, remains a string instead of becoming one of the standard boolean values (true/1 or false/0). This means the server code needs to be written in a way that expects this field to be strings and not a boolean.

Is there a reason why this encoding/decoding is happening?

[8e26d39dd9:/src/preview.js:185 Preview.Preview._callback()](https://github.com/embedly/jquery-preview/blob/8e26d39dd95aa018286339c7324e10f82581f129/src/preview.js#L185):

> `v = obj.hasOwnProperty(n) && obj[n] ? encodeURIComponent(obj[n]): '';`

[8e26d39dd9::src/preview.js:313 Preview.Preview._submit()](https://github.com/embedly/jquery-preview/blob/8e26d39dd95aa018286339c7324e10f82581f129/src/preview.js#L313):

> `data[n] = decodeURIComponent($(e).val());`