Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core-xhr.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@
for (var n in params) {
var v = params[n];
n = encodeURIComponent(n);
r.push(v == null ? n : (n + '=' + encodeURIComponent(v)));
if (Array.isArray(v)) {
v.forEach(function(val) {
r.push(val == null ? n : (n + '=' + encodeURIComponent(val)));
});
} else {
r.push(v == null ? n : (n + '=' + encodeURIComponent(v)));
}
}
return r.join('&');
},
Expand Down
59 changes: 59 additions & 0 deletions test/core-ajax-multivalue.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>core-ajax</title>
<script src="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../core-ajax.html">
</head>
<body>

<core-ajax></core-ajax>

<script>
suite('multivalue', function(){
var animationFrameFlush = function(callback) {
flush(function(){
requestAnimationFrame(function(){
flush(callback);
});
});
};
var ajax, requests, xhr;
suiteSetup(function(done){
ajax = document.querySelector("core-ajax");
requests = []
xhr = sinon.useFakeXMLHttpRequest();
xhr.onCreate = function(xhr) {
requests.push(xhr);
};
async.series([
function(cb){
ajax.url="http://gdata.youtube.com/feeds/api/videos/";
ajax.params='{"alt":"json", "q":"chrome", "keywords":["chrome", "browser"]}';
ajax.handleAs="json";
ajax.auto=true;
cb();
},
animationFrameFlush
], done);
});

test('Array valued parameters should be properly encoded', function(done) {
var req = requests[0];
assert.match(req.url, /[?&]keywords=chrome/);
assert.match(req.url, /[?&]keywords=browser/);
done();
});
});
</script>
</body>
</html>
3 changes: 2 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
<body>
<script>
WCT.loadSuites([
'core-ajax.html',
'core-ajax-multivalue.html',
'core-ajax-progress.html',
'core-ajax-race.html',
'core-ajax.html'
]);
</script>
</body>
Expand Down