我目前正在使用 Laravel 8 版本開發應用程式。我已經構建了一個名為的組件input-group,它會導致我不理解的編碼問題。組件的代碼如下所示:
<div class="form-group" {{ isset($attributes['style']) ? $attributes->merge(['style' => $attributes['style']]) : null }}>
@if(isset($attributes['label']))
<label for="{{ $attributes['id'] }}">{{ $attributes['label'] }}</label>
<input type="text"
value="{{ isset($attributes['value']) ? $attributes['value'] : null }}"
class="form-control form-control-sm"
name="{{ $attributes['name'] }}"
id="{{ $attributes['id'] }}"
placeholder="{{ isset($attributes['placeholder']) ? $attributes['placeholder'] : null }}">
@else
<input style="width:100%;" type="text" value="{{ isset($attributes['value']) ? $attributes['value'] : null }}" hljs-string">" name="{{ $attributes['name'] }}" id="{{ $attributes['id'] }}" placeholder="{{ isset($attributes['placeholder']) ? $attributes['placeholder'] : null }}">
@endif
</div>
這是我注入到value屬性中的資料=>Inspecteur de l'Education Nationale
這是我在我的輸出中得到的<input>:Inspecteur de l'Education Nationale
我確切地說我的資料庫(使用 mySQL)具有 Laravel 默認編碼utf8mb4_unicode_ci。我用來獲取這些資料的請求是一個經典的 Eloquent 請求(我不操縱編碼)
mysql 驅動程式的配置如下所示:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
uj5u.com熱心網友回復:
{!! !!} 會起作用,但我不會在這里使用它。
特別是如果您渲染的值有可能由用戶設定,因為它是未轉義的。這是一個潛在的漏洞,您很容易受到 XSS 攻擊。
你可以這樣做:
{{ html_entity_decode($value) }},您仍然可以獲得刀片幫助防止 XSS 攻擊的好處。
您可以在此處閱讀有關該功能的更多資訊:https : //www.php.net/manual/en/function.html-entity-decode.php。
uj5u.com熱心網友回復:
使用{!! !!}代替{{ }}
IE :
value="{!! isset($attributes['value']) ? $attributes['value'] : null !!}"
顯示未轉義的資料
默認情況下,
{{ }}通過 PHP 的htmlspecialchars函式自動發送Blade陳述句,以防止 XSS 攻擊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/348193.html
上一篇:如何在@media查詢中禁用
