mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-25 18:06:15 -04:00
Pad: Fix copyPadWithoutHistory
apool corruption bug
This commit is contained in:
parent
ed78b56079
commit
dab881139d
4 changed files with 96 additions and 5 deletions
|
@ -91,6 +91,17 @@ class AttributePool {
|
|||
this.nextNum = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {AttributePool} A deep copy of this attribute pool.
|
||||
*/
|
||||
clone() {
|
||||
const c = new AttributePool();
|
||||
for (const [n, a] of Object.entries(this.numToAttrib)) c.numToAttrib[n] = [a[0], a[1]];
|
||||
Object.assign(c.attribToNum, this.attribToNum);
|
||||
c.nextNum = this.nextNum;
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an attribute to the attribute set, or query for an existing attribute identifier.
|
||||
*
|
||||
|
@ -164,7 +175,10 @@ class AttributePool {
|
|||
|
||||
/**
|
||||
* @returns {Jsonable} An object that can be passed to `fromJsonable` to reconstruct this
|
||||
* attribute pool. The returned object can be converted to JSON.
|
||||
* attribute pool. The returned object can be converted to JSON. WARNING: The returned object
|
||||
* has references to internal state (it is not a deep copy). Use the `clone()` method to copy
|
||||
* a pool -- do NOT do `new AttributePool().fromJsonable(pool.toJsonable())` to copy because
|
||||
* the resulting shared state will lead to pool corruption.
|
||||
*/
|
||||
toJsonable() {
|
||||
return {
|
||||
|
@ -177,7 +191,10 @@ class AttributePool {
|
|||
* Replace the contents of this attribute pool with values from a previous call to `toJsonable`.
|
||||
*
|
||||
* @param {Jsonable} obj - Object returned by `toJsonable` containing the attributes and their
|
||||
* identifiers.
|
||||
* identifiers. WARNING: This function takes ownership of the object (it does not make a deep
|
||||
* copy). Use the `clone()` method to copy a pool -- do NOT do
|
||||
* `new AttributePool().fromJsonable(pool.toJsonable())` to copy because the resulting shared
|
||||
* state will lead to pool corruption.
|
||||
*/
|
||||
fromJsonable(obj) {
|
||||
this.numToAttrib = obj.numToAttrib;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue