PDA

View Full Version : Ext.DomQuery.select failing if comma in selector



vajrakumar.d
4 Feb 2014, 5:44 AM
'Error parsing selector, parsing failed at "' + path + '"';


Hello,

I am trying to Query a node from xml depending on selector , and domquery is throwing error if my select on is having comma in it !


Ext.onReady(function () {
Ext.Ajax.request({
url : 'sample.xml',
success : function (resp, e) {
//var a = Ext.DomQuery.select("root/I[a='abc']", resp.responseXML);
var b = Ext.DomQuery.select("root/I[@a='abc']", resp.responseXML);
var c = Ext.DomQuery.select("root/I[a='abc'd']", resp.responseXML);
var d = Ext.DomQuery.select("root/I[a='[email protected]']", resp.responseXML);
//All the above are working fine

//Below line is not at all working
var d = Ext.DomQuery.select("root/I[a='abc,d']", resp.responseXML);
// throwing error as : 'Error parsing selector, parsing failed at "' + path + '"'; at line 1126 in ext-all-debug.js


},
failure : function (resp, e) {
debugger;
}
});
});


And my xml is as follows :


<root> <I a="abc"/> <I a="abc'd"/> <I a="[email protected]"/> <I a="abc,d"/> <I a="abc!d"/></root>

I have used this selector lot of places in my code and this is just a sample. Always this selector ( here "abc,d" ) will be coming from a variable and it is dynamic. No one knows when comma comes and when not. how to handle this issue ? Is there any fix for this ?

Update :

Tried all escape sequences like :


var d = Ext.DomQuery.select("root/I[a='abc\,d']", resp.responseXML);
var d = Ext.DomQuery.select("root/I[a='abc\\,d']", resp.responseXML);
var d = Ext.DomQuery.select("root/I[a='abc\\\,d']", resp.responseXML);

But didnt work. Same Error.

LesJ
4 Feb 2014, 6:57 AM
Try to escape it: \,

vajrakumar.d
4 Feb 2014, 9:32 PM
Hi,
thanks for reply. I tried all \ , \\, \\\ for escaping that comma. It was not working. Forgot to mention it in Question.

burnnat
5 Feb 2014, 2:43 PM
This appears to be a bug in the code for Ext.dom.Query. If you look at the code for Ext.dom.Query.jsSelect() (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.dom.Query-method-jsSelect), you see this near the top:

jsSelect: function(path, root, type) {
// set root to doc if not specified.
root = root || doc;

if (typeof root == "string") {
root = doc.getElementById(root);
}
var paths = path.split(","),
results = [],
i, len, subPath, result;

// ...
}

Notice the part that says paths = path.split(",")? Under normal circumstances, this allows you to specify multiple selectors (like in CSS), but it doesn't take into account the fact that there may be commas inside attributes like you have. This is a deficiency in the logic for Ext.dom.Query, and Sencha should fix this (in my opinion).

There is, however, a workaround. Your query string can contain unicode escape sequences, and luckily, these escape sequences are not converted into their raw characters until after the query is split. This means that you can specify your comma according to its unicode codepoint (U+002C) and the query will work as expected. So in your example, this would work:

Ext.DomQuery.select("root/I[a='abc\\00002cd']", resp.responseXML);

If your query strings are dynamically, you'll need to add some extra handling to convert any commas to \00002c, but that should at least get your queries to run correctly.

nohuhu
7 Feb 2014, 4:31 PM
The fix is going to be available in 4.2.3; it is now possible to escape the commas:



var d = Ext.DomQuery.select("root/I[a='abc\\,d']", resp.responseXML);


Regards,
Alex.