PDA

View Full Version : [CLOSED] [4.2.1] Ext.state.Provider cannot read strings with line breaks



burnnat
6 Nov 2013, 1:56 PM
Ext version tested:
Ext 4.2.1

Browser versions tested against:
Firefox 24 Chrome 30

Description:

Ext.state.Provider objects fail to retrieve stored strings that contain newlines.
Note that this bug appears to have been around for at least a year (http://www.sencha.com/forum/showthread.php?244539-Ext.state.Provider-encode-decode-issue-when-a-string-contains-line-breaks).


Steps to reproduce the problem:

Instantiate an Ext.state.Provider (like LocalStorageProvider, or CookieProvider).
Using Ext.state.Provider#set() (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.state.Provider-method-set), store a string value that contains at least one newline.
Attempt to retrieve that value using Ext.state.Provider#get() (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.state.Provider-method-get).


The result that was expected:
The retrieved value should be identical to the stored value.

The result that occurs instead:
The retrieved value is undefined.

Sencha Fiddle:

1dd

Debugging already done:
The issue appears to be that the regular expression used in the provider's decodeValue() (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.state.Provider-method-decodeValue) method doesn't capture newlines (since in Javascript, the "dot" character in regular expressions does not match line breaks).

Possible fix:
On line 105 of Provider.js, modify the regex to include newlines:

re = /^(a|n|d|b|s|o|e)\:([\s\S]*)$/


Override workaround:

/**
* @private
*/
Ext.define('Gateway.overrides.debug.StateNewlines', {
override: 'Ext.state.Provider',

decodeValue: function(value) {
var re = /^s\:([\s\S]*)$/;
var matches = re.exec(unescape(value));

if (matches) {
return matches[1];
}
else {
return this.callParent(arguments);
}
}
});

Gary Schlosberg
6 Nov 2013, 2:30 PM
Thanks for the report! I have opened a bug in our bug tracker.