Results 1 to 5 of 5

Thread: Ext.state.Provider encode / decode issue when a string contains line breaks

  1. #1
    Sencha Premium Member
    Join Date
    Oct 2009
    Posts
    106

    Default Ext.state.Provider encode / decode issue when a string contains line breaks

    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':
    Code:
    //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.

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    Is it the encodeValue or decodeValue method that is breaking?
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3
    Sencha Premium Member
    Join Date
    Oct 2009
    Posts
    106

    Default

    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.
    Code:
    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!

  4. #4

    Default

    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.

  5. #5
    Ext JS Premium Member burnnat's Avatar
    Join Date
    Jun 2011
    Posts
    418
    Answers
    42

    Default

    See also this bug report for the same issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •