Bug 1103908 - Handle unicode room names properly for Loop. r=mikedeboer

This commit is contained in:
Mark Banner 2014-12-10 22:45:18 +00:00
Родитель 3d4b310ad1
Коммит 2a4da06dce
3 изменённых файлов: 55 добавлений и 0 удалений

Просмотреть файл

@ -456,6 +456,20 @@ let MozLoopServiceInternal = {
2 * 32, true);
}
if (payloadObj) {
// Note: we must copy the object rather than mutate it, to avoid
// mutating the values of the object passed in.
let newPayloadObj = {};
for (let property of Object.getOwnPropertyNames(payloadObj)) {
if (typeof payloadObj[property] == "string") {
newPayloadObj[property] = CommonUtils.encodeUTF8(payloadObj[property]);
} else {
newPayloadObj[property] = payloadObj[property];
}
};
payloadObj = newPayloadObj;
}
return gHawkClient.request(path, method, credentials, payloadObj).then((result) => {
this.clearError("network");
return result;

Просмотреть файл

@ -0,0 +1,40 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Unit tests for handling hawkRequest
*/
"use strict";
Cu.import("resource://services-common/utils.js");
add_task(function* request_with_unicode() {
const unicodeName = "yøü";
loopServer.registerPathHandler("/fake", (request, response) => {
let body = CommonUtils.readBytesFromInputStream(request.bodyInputStream);
let jsonBody = JSON.parse(body);
Assert.equal(jsonBody.name, CommonUtils.encodeUTF8(unicodeName));
response.setStatusLine(null, 200, "OK");
response.processAsync();
response.finish();
});
yield MozLoopServiceInternal.hawkRequestInternal(LOOP_SESSION_TYPE.GUEST, "/fake", "POST", {name: unicodeName}).then(
() => Assert.ok(true, "Should have accepted"),
() => Assert.ok(false, "Should have accepted"));
});
function run_test() {
setupFakeLoopServer();
do_register_cleanup(() => {
Services.prefs.clearUserPref("loop.hawk-session-token");
Services.prefs.clearUserPref("loop.hawk-session-token.fxa");
MozLoopService.errors.clear();
});
run_next_test();
}

Просмотреть файл

@ -11,6 +11,7 @@ skip-if = toolkit == 'gonk'
[test_loopservice_dnd.js]
[test_loopservice_expiry.js]
[test_loopservice_hawk_errors.js]
[test_loopservice_hawk_request.js]
[test_loopservice_loop_prefs.js]
[test_loopservice_initialize.js]
[test_loopservice_locales.js]