apostrophe 4.5.1 → 4.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.5.2 (2024-07-11)
4
+
5
+ ### Fixes
6
+
7
+ * Ensure that `apos.doc.walk` never gets caught in an infinite loop even if circular references are present in the data. This is a hotfix for an issue that can arise when the new support for breadcrumbs in search results is combined with a more inclusive projection for page ancestors.
8
+ * Correct a longstanding bug in `apos.doc.walk` that led items to be listed twice in the `ancestors` array passed to the iterator.
9
+ * Correct a longstanding bug in `apos.doc.walk` that led ancestors that are themselves arrays to be misrepresented as a series of objects in the `ancestors` array passed to the iterator.
10
+ * For additional guarantees of reliability the `_dotPath` and `_ancestors` arguments to `apos.doc.walk`, which were always clearly documented as for internal use only, can no longer be passed in externally.
11
+
3
12
  ## 4.5.1 (2024-07-11)
4
13
 
5
14
  ### Changes
@@ -786,39 +786,40 @@ module.exports = {
786
786
  // will be `b`, the value will be `5`, the dotPath
787
787
  // will be the string `a.b`, and ancestors will be
788
788
  // [ { a: { b: 5 } } ].
789
- //
790
- // You do not need to pass the `_dotPath` and `_ancestors` arguments.
791
- // They are used for recursive invocation.
792
- walk(doc, iterator, _dotPath, _ancestors) {
793
- // We do not use lodash here because of
794
- // performance issues.
795
- //
796
- // Pruning big nested objects is not something we
797
- // can afford to do slowly. -Tom
798
- if (_dotPath !== undefined) {
799
- _dotPath += '.';
800
- } else {
801
- _dotPath = '';
802
- }
803
- _ancestors = (_ancestors || []).concat(doc);
804
- const remove = [];
805
- for (const key in doc) {
806
- const __dotPath = _dotPath + key.toString();
807
- const ow = '_originalWidgets';
808
- if (__dotPath === ow || __dotPath.substring(0, ow.length) === ow + '.') {
809
- continue;
789
+ walk(doc, iterator) {
790
+ return walkBody(doc, iterator, undefined, []);
791
+ function walkBody(doc, iterator, _dotPath, _ancestors) {
792
+ if (_ancestors.includes(doc)) {
793
+ // No infinite loops on circular references
794
+ return;
810
795
  }
811
- if (iterator(doc, key, doc[key], __dotPath, _ancestors) === false) {
812
- remove.push(key);
796
+ // Don't use concat, doc can be an array in which case
797
+ // it is important to preserve the nesting
798
+ _ancestors = [ ..._ancestors, doc ];
799
+ if (_dotPath !== undefined) {
800
+ _dotPath += '.';
813
801
  } else {
814
- const val = doc[key];
815
- if (typeof val === 'object') {
816
- self.walk(val, iterator, __dotPath, _ancestors.concat([ doc ]));
802
+ _dotPath = '';
803
+ }
804
+ const remove = [];
805
+ for (const key in doc) {
806
+ const __dotPath = _dotPath + key.toString();
807
+ const ow = '_originalWidgets';
808
+ if (__dotPath === ow || __dotPath.substring(0, ow.length) === ow + '.') {
809
+ continue;
810
+ }
811
+ if (iterator(doc, key, doc[key], __dotPath, _ancestors) === false) {
812
+ remove.push(key);
813
+ } else {
814
+ const val = doc[key];
815
+ if (typeof val === 'object') {
816
+ walkBody(val, iterator, __dotPath, _ancestors);
817
+ }
817
818
  }
818
819
  }
819
- }
820
- for (const key of remove) {
821
- delete doc[key];
820
+ for (const key of remove) {
821
+ delete doc[key];
822
+ }
822
823
  }
823
824
  },
824
825
  // Retry the given "actor" async function until it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apostrophe",
3
- "version": "4.5.1",
3
+ "version": "4.5.2",
4
4
  "description": "The Apostrophe Content Management System.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -148,4 +148,4 @@
148
148
  "browserslist": [
149
149
  "ie >= 10"
150
150
  ]
151
- }
151
+ }