diff options
author | Jordan <jordan.hollinger@gmail.com> | 2011-12-16 15:41:11 -0500 |
---|---|---|
committer | Jordan <jordan.hollinger@gmail.com> | 2011-12-16 15:41:11 -0500 |
commit | e8ef99fb728aa792e697e29542ae15b5c06bc774 (patch) | |
tree | 4dc504cadd6f7b883c5104400f8b3265dbadb170 /node/db | |
parent | ddf1cd345c8516a77c1440b53ddc05279551db7b (diff) | |
download | etherpad-lite-e8ef99fb728aa792e697e29542ae15b5c06bc774.zip |
Sanitize pad names
Diffstat (limited to 'node/db')
-rw-r--r-- | node/db/PadManager.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/node/db/PadManager.js b/node/db/PadManager.js index 36c27263..1aadcd1f 100644 --- a/node/db/PadManager.js +++ b/node/db/PadManager.js @@ -39,6 +39,14 @@ var globalPads = { }; /** + * An array of padId transformations. These represent changes in pad name policy over + * time, and allow us to "play back" these changes so legacy padIds can be found. + */ +var padIdTransforms = [ + [/\s+/g, '_'] +]; + +/** * Returns a Pad Object with the callback * @param id A String with the id of the pad * @param {Function} callback @@ -110,6 +118,39 @@ exports.doesPadExists = function(padId, callback) }); } +//returns a sanitized padId, respecting legacy pad id formats +exports.sanitizePadId = function(padId, callback) { + var transform_index = arguments[2] || 0; + //we're out of possible transformations, so just return it + if(transform_index >= padIdTransforms.length) + { + callback(padId); + } + //check if padId exists + else + { + exports.doesPadExists(padId, function(junk, exists) + { + if(exists) + { + callback(padId); + } + else + { + //get the next transformation *that's different* + var transformedPadId = padId; + while(transformedPadId == padId && transform_index < padIdTransforms.length) + { + transformedPadId = padId.replace(padIdTransforms[transform_index][0], padIdTransforms[transform_index][1]); + transform_index += 1; + } + //check the next transform + exports.sanitizePadId(transformedPadId, callback, transform_index); + } + }); + } +} + exports.isValidPadId = function(padId) { return /^(g.[a-zA-Z0-9]{16}\$)?[^$]{1,50}$/.test(padId); |