Bug 1057137 - Broken menu: NS_ERROR_ILLEGAL_VALUE: id, attribute, or value too long. r=enn

This commit is contained in:
Roberto A. Vitillo 2014-08-29 06:52:00 +02:00
parent a4067dc3d5
commit eb28461a73
2 changed files with 23 additions and 2 deletions

View File

@ -201,8 +201,14 @@ XULStore.prototype = {
}
// bug 319846 -- don't save really long attributes or values.
if (id.length > 1024 || attr.length > 1024 || value.length > 1024)
throw Components.Exception("id, attribute, or value too long", Cr.NS_ERROR_ILLEGAL_VALUE);
if (id.length > 512 || attr.length > 512) {
throw Components.Exception("id or attribute name too long", Cr.NS_ERROR_ILLEGAL_VALUE);
}
if (value.length > 4096) {
Services.console.logStringMessage("XULStore: Warning, truncating long attribute value")
value = value.substr(0, 4096);
}
let obj = this._data;
if (!(docURI in obj)) {

View File

@ -97,6 +97,21 @@ add_task(function* testImport(){
checkOldStore();
});
add_task(function* testTruncation() {
let dos = Array(8192).join("~");
// Long id names should trigger an exception
Assert.throws(() => XULStore.setValue(browserURI, dos, "foo", "foo"), /NS_ERROR_ILLEGAL_VALUE/);
// Long attr names should trigger an exception
Assert.throws(() => XULStore.setValue(browserURI, "foo", dos, "foo"), /NS_ERROR_ILLEGAL_VALUE/);
// Long values should be truncated
XULStore.setValue(browserURI, "dos", "dos", dos);
dos =XULStore.getValue(browserURI, "dos", "dos");
do_check_true(dos.length == 4096)
XULStore.removeValue(browserURI, "dos", "dos")
});
add_task(function* testGetValue() {
// Get non-existing property
checkValue(browserURI, "side-window", "height", "");