shared

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package shared holds PHP behaviour that runner and stdlib both need.

stdlib imports runner, never the reverse, so a behaviour both perform has nowhere to live in either. Form decoding is the case: runner builds $_GET and $_POST, parse_str() does the same to a string, and the two have to agree.

Only that. A helper stdlib alone needs belongs in internal/phpval; one only runner needs belongs in runner.

Index

Constants

View Source
const (
	DefaultMaxNesting = 64
	DefaultMaxVars    = 1000
)

Variables

This section is empty.

Functions

func ParsePairs

func ParsePairs(pairs []Pair, limits Limits) *model.Array

ParsePairs is ParseStr for input that arrived as pairs: multipart values and the cookie header. Order is the order they are applied in, which decides the result when two name the same variable.

func ParseStr

func ParseStr(raw string, limits Limits) *model.Array

ParseStr decodes an application/x-www-form-urlencoded string into the nested array PHP builds from it. It backs parse_str(), $_GET and $_POST.

Decoding happens before the brackets are read, so `k%5Ba%20b%5D=1` nests under the key `a b`.

func RawURLDecode

func RawURLDecode(s string) string

RawURLDecode decodes an RFC 3986 string: as URLDecode, but `+` is a plus.

func URLDecode

func URLDecode(s string) string

URLDecode decodes an application/x-www-form-urlencoded string.

Lenient, because PHP is: `a=%zz` decodes to the literal `%zz`. net/url refuses the same input and drops the whole pair, which loses a field a browser did send.

Types

type Limits

type Limits struct {
	// MaxNesting is php.ini's max_input_nesting_level. A variable past it is
	// dropped whole rather than truncated.
	MaxNesting int

	// MaxVars is php.ini's max_input_vars.
	MaxVars int
}

Limits bounds what a hostile form can build. A zero field means PHP's default; negative means no limit.

type Pair

type Pair struct {
	Name  string
	Value string
}

Pair is one form field, name and value already decoded.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL