|
474 | 474 |
|
475 | 475 | // For non-atomic types, visit all properties and update recursively |
476 | 476 | visitPropertiesOrArrayEntries(rootObject, function(indexer) { |
477 | | - var fullPropertyName = parentPropertyName.length ? parentPropertyName + "." + indexer : indexer; |
| 477 | + var fullPropertyName = parentPropertyName.length ? parentPropertyName + "." + escapePropertyNameComponent(indexer) : escapePropertyNameComponent(indexer); |
478 | 478 |
|
479 | 479 | if (ko.utils.arrayIndexOf(options.ignore, fullPropertyName) !== -1) { |
480 | 480 | return; |
|
623 | 623 | for (i = 0, j = editScript.length; i < j; i++) { |
624 | 624 | key = editScript[i]; |
625 | 625 | var mappedItem; |
626 | | - var fullPropertyName = parentPropertyName + "[" + i + "]"; |
| 626 | + var fullPropertyName = parentPropertyName + "[" + escapePropertyNameComponent(i) + "]"; |
| 627 | + |
627 | 628 | switch (key.status) { |
628 | 629 | case "added": |
629 | 630 | item = optimizedKeys ? itemsByKey[key.value] : getItemByKey(ko.utils.unwrapObservable(rootObject), key.value, keyCallback); |
|
740 | 741 | var propertyName = parentName || ""; |
741 | 742 | if (exports.getType(parent) === "array") { |
742 | 743 | if (parentName) { |
743 | | - propertyName += "[" + indexer + "]"; |
| 744 | + propertyName += "[" + escapePropertyNameComponent(indexer) + "]"; |
744 | 745 | } |
745 | 746 | } |
746 | 747 | else { |
747 | 748 | if (parentName) { |
748 | 749 | propertyName += "."; |
749 | 750 | } |
750 | | - propertyName += indexer; |
| 751 | + propertyName += escapePropertyNameComponent(indexer); |
751 | 752 | } |
752 | 753 | return propertyName; |
753 | 754 | } |
754 | 755 |
|
| 756 | + function escapePropertyNameComponent(indexer) { |
| 757 | + var escapedIndexer = (''+indexer) |
| 758 | + .replace(/~/g, '~~') |
| 759 | + .replace(/\[/g, '~[') |
| 760 | + .replace(/]/g, '~]') |
| 761 | + .replace(/\./g, '~.'); |
| 762 | + return escapedIndexer; |
| 763 | + } |
| 764 | + |
| 765 | + |
755 | 766 | exports.visitModel = function(rootObject, callback, options) { |
756 | 767 | options = options || {}; |
757 | 768 | options.visitedObjects = options.visitedObjects || new ObjectLookup(); |
|
774 | 785 |
|
775 | 786 | var parentName = options.parentName; |
776 | 787 | visitPropertiesOrArrayEntries(unwrappedRootObject, function(indexer) { |
777 | | - if (options.ignore && ko.utils.arrayIndexOf(options.ignore, indexer) !== -1) return; |
| 788 | + var escapedIndexer = escapePropertyNameComponent(indexer); |
| 789 | + if (options.ignore && ko.utils.arrayIndexOf(options.ignore, escapedIndexer) != -1) return; |
778 | 790 |
|
779 | 791 | var propertyValue = unwrappedRootObject[indexer]; |
780 | 792 | options.parentName = getPropertyName(parentName, unwrappedRootObject, indexer); |
781 | 793 |
|
782 | 794 | // If we don't want to explicitly copy the unmapped property... |
783 | | - if (ko.utils.arrayIndexOf(options.copy, indexer) === -1) { |
| 795 | + if (ko.utils.arrayIndexOf(options.copy, escapedIndexer) === -1) { |
784 | 796 | // ...find out if it's a property we want to explicitly include |
785 | | - if (ko.utils.arrayIndexOf(options.include, indexer) === -1) { |
| 797 | + if (ko.utils.arrayIndexOf(options.include, escapedIndexer) === -1) { |
786 | 798 | // The mapped properties object contains all the properties that were part of the original object. |
787 | 799 | // If a property does not exist, and it is not because it is part of an array (e.g. "myProp[3]"), then it should not be unmapped. |
788 | 800 | var unwrappedRootMappingProperty = unwrappedRootObject[mappingProperty]; |
789 | 801 | if (unwrappedRootMappingProperty) { |
790 | 802 | var mappedProperties = unwrappedRootMappingProperty.mappedProperties; |
791 | | - if (mappedProperties && !mappedProperties[indexer]) { |
| 803 | + if (mappedProperties && !mappedProperties[escapedIndexer]) { |
792 | 804 | var copiedProperties = unwrappedRootMappingProperty.copiedProperties; |
793 | | - if (copiedProperties && !copiedProperties[indexer] && (exports.getType(unwrappedRootObject) !== "array")) { |
| 805 | + if (copiedProperties && !copiedProperties[escapedIndexer] && (exports.getType(unwrappedRootObject) !== "array")) { |
794 | 806 | return; |
795 | 807 | } |
796 | 808 | } |
|
0 commit comments