# model.ContentMatch.edge can return nullable fields

**URL:** <https://discuss.prosemirror.net/t/model-contentmatch-edge-can-return-nullable-fields/2321>\
**Category:** Uncategorized\
**Created:** [November 5, 2019, 4:40pm UTC](https://discuss.prosemirror.net/t/model-contentmatch-edge-can-return-nullable-fields/2321 "2019-11-05T16:40:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsnobip](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/tsnobip/32/1210_2.png) [@tsnobip](https://discuss.prosemirror.net/u/tsnobip)\
**Post date:** [November 5, 2019, 4:40pm UTC](https://discuss.prosemirror.net/t/model-contentmatch-edge-can-return-nullable-fields/2321/1 "2019-11-05T16:40:27Z")

</div>

Hi,

I’ve noticed than unlike what’s stated in the [docs](https://prosemirror.net/docs/ref/#model.ContentMatch.edge), model.ContentMatch.edge can return nullable fields. Indeed, it we look at the [sources](https://github.com/ProseMirror/prosemirror-model/blob/aee0ed9c24f3f38e003d03dfb39b76496d21b924/src/content.js#L139), it should throw a `RangeError` if `i >= this.next.length` instead of `i > this.next.length` like it is right now, if we consider _n_ starts at 0 (maybe this should be clarified too).

I can create an Issue and/or a PR if needed.

Thanks for all the huge work you’ve done

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [November 7, 2019, 9:43am UTC](https://discuss.prosemirror.net/t/model-contentmatch-edge-can-return-nullable-fields/2321/2 "2019-11-07T09:43:07Z")

</div>

Thanks for pointing that out. I’ve fixed it, since I also noticed an issue in the doc comment just now, and wanted to fix that as well.

---

<div class="post-metadata">

**Author:** ![tsnobip](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/tsnobip/32/1210_2.png) [@tsnobip](https://discuss.prosemirror.net/u/tsnobip)\
**Post date:** [November 7, 2019, 11:59am UTC](https://discuss.prosemirror.net/t/model-contentmatch-edge-can-return-nullable-fields/2321/3 "2019-11-07T11:59:47Z")

</div>

Thanks for the very quick fix! I discovered the zero-width space character thanks to that, I also saw the bug in the docs but had no idea how to fix it. It could probably throw a `RangeError` if `i < 0` too but I guess I’m too influenced by my static typing background ^^

---

<div class="post-metadata">

**Author:** ![tsnobip](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/tsnobip/32/1210_2.png) [@tsnobip](https://discuss.prosemirror.net/u/tsnobip)\
**Post date:** [November 7, 2019, 12:24pm UTC](https://discuss.prosemirror.net/t/model-contentmatch-edge-can-return-nullable-fields/2321/4 "2019-11-07T12:24:05Z")

</div>

Throwing a RangeError in [resolveDepth](https://github.com/ProseMirror/prosemirror-model/blob/847ff8e3316f9914970e6d1707e236b6b44fd45b/src/resolvedpos.js#L25) of ResolvedPos when `depth < -this.depth || depth >= this.depth` would also ensure that `node` and `index` functions don’t return `null` values and that `indexAfter`, `start`, `end`, `before`, `after` functions don’t return potentially incoherent numbers.
