Construct FQL safely
An embedding application provides two different inputs to Ferret: FQL source to compile and runtime values for that source to consume. Keep that boundary explicit.
FQL source is code. Do not insert runtime data with fmt.Sprintf or string concatenation. URLs, CSS selectors, HTML, credentials, identifiers, request bodies, and configuration values should normally be passed as engine or session parameters.
Parameterize runtime values
Interpolating a value into FQL makes the value part of the source text. Quotes or other FQL syntax in that value can change the program or make it fail to compile.
Do not construct a query like this:
Compile stable FQL that references @url, then provide the URL when creating a session:
The engine owns the configured HTML module. The plan contains compiled FQL code, and each session supplies the data for one execution.
Use engine parameters for stable application-wide values and session parameters for per-execution values. Both keep values out of the source text. See Parameters for the complete API.
Pass selectors as parameters
A CSS selector is runtime data when it comes from a request, configuration file, database, or another host input. Pass it separately even when the FQL program uses it as a query selector:
The selector remains a runtime string. It cannot add FQL statements or change the structure of the compiled plan.
Pass existing HTML as a parameter
When the host already has HTML, pass the content to web::html::parse as a parameter instead of embedding it in a string literal:
This preserves the HTML exactly as input data, including quotes, backticks, and text that resembles FQL syntax. For module setup, structured result decoding, and returning modified markup, see Process existing HTML.
Compose source only from authored FQL
An intentionally authored FQL fragment is code, so an application may compose it into a larger FQL source. Runtime data consumed by that fragment must still be passed separately.
Here predicate is deliberately authored FQL code. items and maxPrice are runtime data and remain parameters.