mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 17:33:23 +00:00
[Duplicate] Handle single-element ID arrays
Avoid type coercion related errors when testing to see if a value is an ID that needs to be remapped.
This commit is contained in:
parent
995d71f901
commit
5f96861c44
@ -114,15 +114,19 @@ define(
|
||||
* @private
|
||||
*/
|
||||
CopyTask.prototype.rewriteIdentifiers = function (obj, idMap) {
|
||||
function lookupValue(value) {
|
||||
return (typeof value === 'string' && idMap[value]) || value;
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
obj.forEach(function (value, index) {
|
||||
obj[index] = idMap[value] || value;
|
||||
obj[index] = lookupValue(value);
|
||||
this.rewriteIdentifiers(obj[index], idMap);
|
||||
}, this);
|
||||
} else if (obj && typeof obj === 'object') {
|
||||
Object.keys(obj).forEach(function (key) {
|
||||
var value = obj[key];
|
||||
obj[key] = idMap[value] || value;
|
||||
obj[key] = lookupValue(value);
|
||||
if (idMap[key]) {
|
||||
delete obj[key];
|
||||
obj[idMap[key]] = value;
|
||||
|
Loading…
x
Reference in New Issue
Block a user