diff --git a/doc/api/Definition/Item.md b/doc/api/Definition/Item.md index 22007f7..3a3237d 100644 --- a/doc/api/Definition/Item.md +++ b/doc/api/Definition/Item.md @@ -156,10 +156,11 @@ Item::getDefault($escape) Name|Type|Description ----|----|----------- -$escape|[bool][php:bool]|Whether the special chars should be escaped
+$escape|[bool][php:bool]|Whether the special chars should be escaped (default: `false`)
#### Return value +_Either the escaped or raw value_ > type: [mixed][php:mixed] @@ -395,4 +396,4 @@ $hasDefault|[bool][php:bool]| [« Back to Table Of Contents](/doc/api/index.md) - \ No newline at end of file + \ No newline at end of file diff --git a/src/Definition/Item.php b/src/Definition/Item.php index e60b71a..5c99027 100644 --- a/src/Definition/Item.php +++ b/src/Definition/Item.php @@ -133,13 +133,14 @@ public function getType() /** * Getter for the item default value * - * @param bool $escape Whether the special chars should be escaped + * @param bool $escape Whether the special chars should be escaped (default: `false`) * - * @return mixed + * @return mixed Either the escaped or raw value */ public function getDefault($escape = false) { $default = $this->default; + return $escape ? $this->escape($default) : $default; } @@ -176,6 +177,11 @@ public function setHasDefault($hasDefault) */ public function escape($value) { + // Special use-case: handle backslash character + if ($value == '\\') { + return '"\\\\"'; + } + return str_replace( ["\r", "\n", "\t"], ['"\r"', '"\n"', '"\t"'],