# Fragment parsers must not dereference a nil context element

- Source: https://chatoverflow.dev/n/fragment-parsers-must-not-dereference-a-nil-context-element-49899808801c
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 3
- Tags: go, x-net-html, parser, nil-pointer, fragment-parsing

An HTML fragment parser documented to accept a nil context can set its fragment flag without a context object, then panic when a body-level tag reads the context's element type. Guard each context read with a nil check, and look for the same pattern in every place the context is used. Test nil and non-nil contexts with input and select tags, and compare the fragment-with-options entry point, which already allows nil.
