oSettings.oPreviousSearch.sSearch is not encoded while saving in cookie

oSettings.oPreviousSearch.sSearch is not encoded while saving in cookie

WhatEverWhatEver Posts: 8Questions: 0Answers: 0
edited January 2010 in Bug reports
Hi all,

I've noticed that the value of oSettings.oPreviousSearch.sSearch is not encoded while saving in cookie with bStateSave enabled. As far as the page charset as well as filter value could be defined not only in UTF or latin, some kind of encoding should be applied (i guess encodeURI/decodeURI should be enough - at least it makes a tric for cyrilic)

WBR,
Andrew

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi Andrew,

    Thanks for noting this - I hadn't really considered what would happen if using a character set other than UTF-x when saving the cookie. Slightly surprised the browser doesn't deal with it for us... So to support other character sets, all that is needed is encodeURI/decodeURI? Are they multi-character set aware? I'm struggling enough with getting TableTools and Flash to work with UTF-16 at the moment... :-)

    Regards,
    Allan
  • kharr0kharr0 Posts: 4Questions: 0Answers: 0
    edited January 2010
    Getting the error at the bottom w/ bStateSave enabled. Error occurs at page load. My script immediately below:

    var oTable;
    $(document).ready(function () {

    oTable = $('#workbench').dataTable({
    "bPaginate": true,
    "sPaginationType": "full_numbers",
    "iDisplayLength": 20,
    "bLengthChange": false,
    "bFilter": false,
    "bInfo": false,
    "bAutoWidth": true,
    "aoColumns": [ {"bSearchable": false}, null, null, {"bSearchable": false} ],
    "bStateSave": true
    });

    $('#tbSearch').keyup(function () {
    var searchText = this.value;
    oTable.fnFilter(searchText);
    });

    });

    ERROR:

    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
    Timestamp: Wed, 20 Jan 2010 15:42:22 UTC


    Message: 'oPreviousSearch.sSearch' is null or not an object
    Line: 453
    Char: 53
    Code: 0
    URI: http://localhost:49618/Scripts/jquery.dataTables.min.js
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Odd - state saving seems to work here: http://datatables.net/examples/basic_init/state_save.html . Does your state cookie include valid JSON?

    Thanks,
    Allan
  • kharr0kharr0 Posts: 4Questions: 0Answers: 0
    Indeed - I have other places where it works fine as well.

    Looks like its because the table's id is the same as tables I'm using elsewhere. I changed the id and all is good. Might be something to point out in the docs.... Either that or make the cookie use a unique id.

    All in all, though, DataTable is a nice piece of kit.

    Thanks!

    -k
  • WhatEverWhatEver Posts: 8Questions: 0Answers: 0
    Hello Allan,

    As far as I know encodeUri writes the string as utf-8 and encodes the utf-8 byte stream. Javascript uses UTF-16 internally, where each character is represented by two bytes, with the exception of a certain group which are represented by 4 (2 bytes for the character and 2 bytes for a modifier of that character).

    Thus, from my perspective encodeUri/decodeUri or econdeURIComponent/decodeURIComponent (or even escape) would be enough in most scenarios

    Kind regards,
    Andrew
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi Andrew,

    In DataTables 1.6.1, the cookie value is encoded using encodeURIComponent() - which should make this safe.

    Regards,
    Allan
This discussion has been closed.