[Pkg-javascript-commits] [dojo] 83/88: When there's a querySelectorAll in the DOM, but no qSA in responseXml, parse responseText with DOMParser. (1.8 backport) refs #15631 !strict
David Prévot
taffit at moszumanska.debian.org
Thu Aug 21 17:39:42 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag 1.8.5
in repository dojo.
commit 3da67802c64a2d6a90e4c86c7393519c32946797
Author: Bryan Forbes <bryan at reigndropsfall.net>
Date: Wed Apr 24 04:10:45 2013 +0000
When there's a querySelectorAll in the DOM, but no qSA in responseXml, parse responseText with DOMParser. (1.8 backport) refs #15631 !strict
git-svn-id: http://svn.dojotoolkit.org/src/branches/1.8/dojo@31327 560b804f-0ae3-0310-86f3-f6aa0a117693
---
_base/xhr.js | 8 ++++++++
request/handlers.js | 14 +++++++++++++-
tests/_base/xhr.html | 24 ++++++++++++++++++++++++
tests/request/xhr.html | 14 +++++++++++++-
tests/request/xhrXml.php | 9 +++++++++
5 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/_base/xhr.js b/_base/xhr.js
index e1106f1..0d0db8e 100644
--- a/_base/xhr.js
+++ b/_base/xhr.js
@@ -119,6 +119,14 @@ define([
// A contentHandler returning an XML Document parsed from the response data
var result = xhr.responseXML;
+ if(result && has("dom-qsa2.1") && !result.querySelectorAll && has("dom-parser")){
+ // http://bugs.dojotoolkit.org/ticket/15631
+ // IE9 supports a CSS3 querySelectorAll implementation, but the DOM implementation
+ // returned by IE9 xhr.responseXML does not. Manually create the XML DOM to gain
+ // the fuller-featured implementation and avoid bugs caused by the inconsistency
+ result = new DOMParser().parseFromString(xhr.responseText, "application/xml");
+ }
+
if(has("ie")){
if((!result || !result.documentElement)){
//WARNING: this branch used by the xml handling in dojo.io.iframe,
diff --git a/request/handlers.js b/request/handlers.js
index 4b10b59..f88d3bc 100644
--- a/request/handlers.js
+++ b/request/handlers.js
@@ -2,9 +2,13 @@ define([
'../json',
'../_base/kernel',
'../_base/array',
- '../has'
+ '../has',
+ '../selector/_loader' // only included for has() qsa tests
], function(JSON, kernel, array, has){
has.add('activex', typeof ActiveXObject !== 'undefined');
+ has.add('dom-parser', function(global){
+ return 'DOMParser' in global;
+ });
var handleXML;
if(has('activex')){
@@ -19,6 +23,14 @@ define([
handleXML = function(response){
var result = response.data;
+ if(result && has('dom-qsa2.1') && !result.querySelectorAll && has('dom-parser')){
+ // http://bugs.dojotoolkit.org/ticket/15631
+ // IE9 supports a CSS3 querySelectorAll implementation, but the DOM implementation
+ // returned by IE9 xhr.responseXML does not. Manually create the XML DOM to gain
+ // the fuller-featured implementation and avoid bugs caused by the inconsistency
+ result = new DOMParser().parseFromString(response.text, 'application/xml');
+ }
+
if(!result || !result.documentElement){
var text = response.text;
array.some(dp, function(p){
diff --git a/tests/_base/xhr.html b/tests/_base/xhr.html
index 027ed56..6eff09e 100644
--- a/tests/_base/xhr.html
+++ b/tests/_base/xhr.html
@@ -451,6 +451,30 @@
// t.t(td instanceof dojo.Deferred);
return d;
},
+ function xhrXMLQueryable(t){
+ var d = new doh.Deferred();
+
+ dojo.xhrGet({
+ url: "../request/xhrXml.php",
+ handleAs: "xml",
+ handle: function(res, ioArgs){
+ if(res instanceof Error){
+ d.errback(res);
+ return;
+ }
+ try{
+ var results = dojo.query('bar', res);
+ t.is(2, results.length);
+ }catch(e){
+ d.errback(e);
+ return;
+ }
+ d.callback(true);
+ }
+ });
+
+ return d;
+ },
function ioPublish(t){
// TODO: this test needs to be rewritten as it is unreliable with the
diff --git a/tests/request/xhr.html b/tests/request/xhr.html
index fa60efb..5b486bf 100644
--- a/tests/request/xhr.html
+++ b/tests/request/xhr.html
@@ -22,8 +22,9 @@
"dojo/errors/CancelError",
"dojo/has",
"doh",
+ "dojo/query",
"dojo/domReady!"
- ], function(xhr, lang, all, RequestTimeoutError, CancelError, has, doh){
+ ], function(xhr, lang, all, RequestTimeoutError, CancelError, has, doh, query){
var tests = [
function xhrGet(t){
var d = new doh.Deferred();
@@ -267,6 +268,17 @@
});
return d;
+ },
+ function xhrXMLQueryable(t){
+ var d = new doh.Deferred();
+
+ xhr.get('xhrXml.php', {
+ handleAs: 'xml'
+ }).then(d.getTestCallback(function(xmlDoc){
+ var results = query('bar', xmlDoc);
+ t.is(2, results.length);
+ }), lang.hitch(d, 'errback'));
+ return d;
}
];
diff --git a/tests/request/xhrXml.php b/tests/request/xhrXml.php
new file mode 100644
index 0000000..75fa3d4
--- /dev/null
+++ b/tests/request/xhrXml.php
@@ -0,0 +1,9 @@
+<?php
+header("HTTP/1.1 200 OK");
+header("Expires: " . gmdate("D, d M Y H:i:s") . "GMT");
+header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+header("Cache-Control: no-cache, must-revalidate");
+header("Pragma: no-cache");
+header("Content-type: application/xml");
+?><?xml version="1.0" encoding="UTF-8" ?>
+<foo><bar baz='thonk'>blarg</bar><bar>blah</bar></foo>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git
More information about the Pkg-javascript-commits
mailing list