Fix bug 799184 - Multiple calendars with different credentials not working with mail4us.net. r=mmecca

--HG--
extra : rebase_source : d033ecdb95f8ea5eaf45280c6aa817478405ae47
This commit is contained in:
Philipp Kewisch 2012-11-28 17:36:05 +01:00
Родитель acf96e9dc0
Коммит b2aaa6becd
1 изменённых файлов: 24 добавлений и 1 удалений

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

@ -154,7 +154,9 @@ calCalendarManager.prototype = {
// The provider may choose to explicitly disable the
// rewriting, for example if all calendars on a
// domain have the same credentials
authHeader = authHeader.replace(/realm="(.*)"/, 'realm="$1 (' + calendar.name + ')"');
let escapedName = calendar.name.replace('\\', '\\\\', 'g')
.replace('"','\\"', 'g');
authHeader = appendToRealm(authHeader, "(" + escapedName + ")");
channel.setResponseHeader("WWW-Authenticate", authHeader, false);
}
}
@ -1109,3 +1111,24 @@ var gCalendarManagerAddonListener = {
return args.shouldUninstall;
}
};
function appendToRealm(authHeader, appendStr) {
let isEscaped = false;
let idx = authHeader.search(/realm="(.*?)(\\*)"/);
if (idx > -1) {
let remain = authHeader.substr(idx + 7); idx += 7;
while (remain.length && !isEscaped) {
let m = remain.match(/(.*?)(\\*)"/);
idx += m[0].length;
isEscaped = ((m[2].length % 2) == 0);
if (!isEscaped) {
remain = remain.substr(m[0].length);
}
}
return authHeader.substr(0, idx - 1) + " " +
appendStr + authHeader.substr(idx - 1);
} else {
return authHeader;
}
}