Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
toolbar filtering or searching for strings contains backslashes or double quotes
Tags: searching
25/01/2011
00:34
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Tony,

I answered on the question which described problems in the usage of \ (backslash) in the toolbar searching. After I reproduced the problem I found out quickly that it is a bug in jqGrid. To fix the problem I have to make changes in grid.custom.js, grid.base.js, jquery.searchFilter.js and grid.formedit.js files. Here are the list of the changed needed

1) The identical lines 576 and 643 of the file grid.custom.js

ruleGroup += "\"data\":\"" + n + "\"}";

should be changed to the following:

ruleGroup += "\"data\":\"" + n.replace(/\\/g,'\\\\').replace(/\"/g,'\\"') + "\"}";

(it escapes backslashes and double quotes corresponds to requirement of http://www.json.org/)

2) The line 203 of the file grid.base.js 

phrase=phrase.toString().replace(new RegExp('\\"',"g"),'\\"');

 should be replaced to

phrase=phrase.toString().replace(/\\/g,'\\\\').replace(/\"/g,'\\"');

 (not only double quotes, but also backslashes must be escaped inside of the string used in _toStr)

3) The lines 134 and 136 of the file grid.formedit.js should be appended with additional lines which reset non-multisearch parameters in case of multipleSearch:true and vice versa. The problem exist if one use for example single line searching together with the toolbar filtering having stringResult:true. In the case if one first play with toolbar filtering and then clear all toolbar filters and try to use single line searching. It will follow that only the toolbar filter will be used and the filter from the single line searching will be ignored. So the corresponding code fragment of  grid.formedit.js should be

sdata={};
if(p.multipleSearch===false) {
    sdata[p.sField] = filters.rules[0].field;
    sdata[p.sValue] = filters.rules[0].data;
    sdata[p.sOper] = filters.rules[0].op;
    sdata[p.sFilter] = "";
} else {
    sdata[p.sFilter] = filters;
    sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = "";
}
grid[0].p.search = hasFilters;
$.extend(grid[0].p.postData,sdata);

Because of the same reason the lines 580 and 647 of the grid.custom.js

$.extend($t.p.postData,{filters:ruleGroup});

 should be replaced to

$.extend($t.p.postData,{filters:ruleGroup,searchField:"",searchString:"",searchOper:""});

4) In the jquery.searchFilter.js the code fragment

ui.find(".sf").each(function(i) {
    var tField = jQuery(this).find("select[name='field'] :selected").val();
    var tOp = jQuery(this).find("select[name='op'] :selected").val();
    var tData = jQuery(this).find("input.vdata,select.vdata :selected").val();
    tData += "";
    tData = tData.replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
    if (!opts.stringResult) {
        ruleGroup.rules.push({
            field: tField,
            op: tOp,
            data: tData
        });
    } else {
        if (i > 0) ruleGroup += ",";
        ruleGroup += "{\"field\":\"" + tField + "\",";
        ruleGroup += "\"op\":\"" + tOp + "\",";
        ruleGroup += "\"data\":\"" + tData + "\"}";
    }
});

should be replaced to

ui.find(".sf").each(function(i) {
    var tField = jQuery(this).find("select[name='field'] :selected").val();
    var tOp = jQuery(this).find("select[name='op'] :selected").val();
    var tData = jQuery(this).find("input.vdata,select.vdata :selected").val();
    tData += "";
    if (!opts.stringResult) {
        ruleGroup.rules.push({
            field: tField,
            op: tOp,
            data: tData
        });
    } else {
        tData = tData.replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
        if (i > 0) ruleGroup += ",";
        ruleGroup += "{\"field\":\"" + tField + "\",";
        ruleGroup += "\"op\":\"" + tOp + "\",";
        ruleGroup += "\"data\":\"" + tData + "\"}";
    }
});

because backslashes and double quotes should be escaped only inside of JSON string and not in the object properties.

Best regards
Oleg

27/01/2011
14:43
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Oleg,

Thanks again. I wil make and test the needed changes.

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

11/02/2011
07:49
Avatar
dpillay
New Member
Members
Forum Posts: 1
Member Since:
11/02/2011
sp_UserOfflineSmall Offline

Hey Tony,

Has this bug been fixed in 3.8.2? Please let me know, thanks!

- Dinesh.

11/02/2011
18:28
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Dinesh,

you will find the modivied developer version of the jqGrid on GitHub and there are not a part of jQuery 3.8.2. The fixes will be first included in the next version of jqGrid.

Best regards
Oleg 

14/02/2011
21:54
Avatar
eemie
Member
Members
Forum Posts: 3
Member Since:
14/02/2011
sp_UserOfflineSmall Offline

Hi OlegK,

on [1] you can see, how jquery json plugin escape strings. maybe this will help to escape all special chars.

[1] http://code.google.com/p/jquery-json/source/browse/trunk/jquery.json.js

Cheers 🙂

14/02/2011
23:41
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hi eemie,

it seems to me that no other characters should be escaped. On http://www.json.org you can find the following picture

Image Enlarger

It means that only '\\' and '"' must be escaped. Some other characters like '/' could be escaped but not must. So one can use for example '/' exactly like '/' in JSON string and the both encoding will be interpret in the same way. So I don't currently see any other characters which can be enter in the search dialog or search toolbar which should be additionally escaped.

It you do find a character or some combination of characters which do must be escaped it would be very interesting.

Best regards
Oleg 

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
48 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information