mirror of
https://github.com/nasa/openmct.git
synced 2025-06-23 01:18:57 +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:
@ -114,15 +114,19 @@ define(
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
CopyTask.prototype.rewriteIdentifiers = function (obj, idMap) {
|
CopyTask.prototype.rewriteIdentifiers = function (obj, idMap) {
|
||||||
|
function lookupValue(value) {
|
||||||
|
return (typeof value === 'string' && idMap[value]) || value;
|
||||||
|
}
|
||||||
|
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(obj)) {
|
||||||
obj.forEach(function (value, index) {
|
obj.forEach(function (value, index) {
|
||||||
obj[index] = idMap[value] || value;
|
obj[index] = lookupValue(value);
|
||||||
this.rewriteIdentifiers(obj[index], idMap);
|
this.rewriteIdentifiers(obj[index], idMap);
|
||||||
}, this);
|
}, this);
|
||||||
} else if (obj && typeof obj === 'object') {
|
} else if (obj && typeof obj === 'object') {
|
||||||
Object.keys(obj).forEach(function (key) {
|
Object.keys(obj).forEach(function (key) {
|
||||||
var value = obj[key];
|
var value = obj[key];
|
||||||
obj[key] = idMap[value] || value;
|
obj[key] = lookupValue(value);
|
||||||
if (idMap[key]) {
|
if (idMap[key]) {
|
||||||
delete obj[key];
|
delete obj[key];
|
||||||
obj[idMap[key]] = value;
|
obj[idMap[key]] = value;
|
||||||
|
Reference in New Issue
Block a user