Documentation

EscapeFormula
in package

A Formatter to tackle CSV Formula Injection.

Tags
see
http://georgemauer.net/2017/10/07/csv-injection.html

Table of Contents

FORMULA_STARTING_CHARS  = ['=', '-', '+', '@']
Spreadsheet formula starting character.
$escape  : string
Escape character to escape each CSV formula field.
$special_chars  : array<string|int, mixed>
Effective Spreadsheet formula starting characters.
__construct()  : mixed
New instance.
__invoke()  : array<string|int, mixed>
League CSV formatter hook.
escapeRecord()  : array<string|int, mixed>
Escape a CSV record.
getEscape()  : string
Returns the escape character.
getSpecialCharacters()  : array<string|int, string>
Returns the list of character the instance will escape.
escapeField()  : mixed|string
Escape a CSV cell if its content is stringable.
filterSpecialCharacters()  : array<string|int, string>
Filter submitted special characters.
isStringable()  : bool
Tells whether the submitted value is stringable.

Constants

FORMULA_STARTING_CHARS

Spreadsheet formula starting character.

public mixed FORMULA_STARTING_CHARS = ['=', '-', '+', '@']

Properties

$escape

Escape character to escape each CSV formula field.

protected string $escape

$special_chars

Effective Spreadsheet formula starting characters.

protected array<string|int, mixed> $special_chars = []

Methods

__construct()

New instance.

public __construct([string $escape = " " ][, array<string|int, string> $special_chars = [] ]) : mixed
Parameters
$escape : string = " "

escape character to escape each CSV formula field

$special_chars : array<string|int, string> = []

additional spreadsheet formula starting characters

Return values
mixed

__invoke()

League CSV formatter hook.

public __invoke(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
$record : array<string|int, mixed>
Tags
see
escapeRecord
Return values
array<string|int, mixed>

escapeRecord()

Escape a CSV record.

public escapeRecord(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
$record : array<string|int, mixed>
Return values
array<string|int, mixed>

getEscape()

Returns the escape character.

public getEscape() : string
Return values
string

getSpecialCharacters()

Returns the list of character the instance will escape.

public getSpecialCharacters() : array<string|int, string>
Return values
array<string|int, string>

escapeField()

Escape a CSV cell if its content is stringable.

protected escapeField(mixed $cell) : mixed|string
Parameters
$cell : mixed

the content of the cell

Return values
mixed|string

the escaped content

filterSpecialCharacters()

Filter submitted special characters.

protected filterSpecialCharacters(string ...$characters) : array<string|int, string>
Parameters
$characters : string
Tags
throws
InvalidArgumentException

if the string is not a single character

Return values
array<string|int, string>

isStringable()

Tells whether the submitted value is stringable.

protected isStringable(string|object $value) : bool
Parameters
$value : string|object
Return values
bool

Search results