PDA

View Full Version : Ext.state.Provider encode / decode issue when a string contains line breaks



gatherworks
1 Oct 2012, 10:48 AM
While implementing a Ext.state.Provider to persist to a JSON Store, I ran into the issue where a string that contains line breaks does not properly persist. The simple use case is to persist a textarea and add a line break.

This code prints 'undefined':


//s is a string that contains a line break
console.log(this.decodeValue(this.encodeValue(s)));


If you remove the line breaks from s, then things work as expected.

mitchellsimoens
10 Oct 2012, 7:47 AM
Is it the encodeValue or decodeValue method that is breaking?

gatherworks
10 Oct 2012, 9:25 AM
Seems to be a decoding issue... but really hard to tell as they are supposed to be symmetric.

Based on the following test code, it seems that the encoding does not lose data, so I am suspecting decode. Have not looked at the code to give you a firm answer.


var s="X\r\nY\r\nZ";
var p=new Ext.state.Provider();
console.log(p.encodeValue(s));
console.log(p.decodeValue(p.encodeValue(s)));


Output:
s%3AX%0D%0AY%0D%0AZ
undefined

Hope that helps.

Thanks!

MadisonWisconsin
3 Apr 2014, 12:00 PM
I just came across this too. Here's a way to see it.

Go to the docs, or any other page with Ext is loaded, then open the console window and type this:

Ext.state.Manager.setProvider(Ext.create('Ext.state.LocalStorageProvider'));
var provider = Ext.state.Manager.getProvider();

var value = provider.encodeValue('a\nb'); // a newline b
value // "s%3Aa%0Ab"
provider.decodeValue(value); // returns undefined

var value = provider.encodeValue('ab');
value // "s%3Aab"
provider.decodeValue(value); // returns "ab"

So it encodes the string with the \n, but it can't decode it.

burnnat
4 Apr 2014, 7:05 AM
See also this bug report (http://www.sencha.com/forum/showthread.php?275486-4.2.1-Ext.state.Provider-cannot-read-strings-with-line-breaks) for the same issue.