在解析 JSON 格式时,报错:Invalid json Syntax error (基于函数 addcslashes() 自动转义)
1、在网页端的表现为,在请求参数中输入:\ 时,响应 200,进而导致在渲染模板时响应 500。如图1
2、在 阿里云 日志服务 SLS 中查看相应日志,在解析 JSON 格式时,报错:Invalid json Syntax error 。如图2
detail:Invalid json: { "sections": { "3collection_s7mzoitr": { "type": "main-collections", "settings": { "heading": "\GráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트" }, "blocks": { "collection-0": { "type": "collection", "settings": { "id": 119 } } } } } } : Syntax error (View: /var/www/object/resources/views/theme/pages/index.blade.php) {"exception":"[object] (Illuminate\\View\\ViewException(code: 0): Invalid json: { \"sections\": { \"3collection_s7mzoitr\": { \"type\": \"main-collections\", \"settings\": { \"heading\": \"\\GráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트\" }, } } : Syntax error (View: /var/www/object/resources/views/theme/pages/index.blade.php) at /var/www/object/Modules/ThemeSetting/Util/JsonDecoder.php:18) [stacktrace] #0 /./vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(45): Illuminate\\View\\Engines\\CompilerEngine->handleViewException(Object(RuntimeException), 0) #1 /./vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\\View\\Engines\\PhpEngine->evaluatePath('/var/www/object/...', Array) #2 /./vendor/laravel/framework/src/Illuminate/View/View.php(143): Illuminate\\View\\Engines\\CompilerEngine->get('/var/www/object/...', Array) #3 /./vendor/laravel/framework/src/Illuminate/View/View.php(126): Illuminate\\View\\View->getContents() #4 /./vendor/laravel/framework/src/Illuminate/View/View.php(91): Illuminate\\View\\View->renderContents() #5 /./vendor/laravel/framework/src/Illuminate/Http/Response.php(42): Illuminate\\View\\View->render() #6 /./vendor/symfony/http-foundation/Response.php(205): Illuminate\\Http\\Response->setContent(Object(Illuminate\\View\\View)) #7 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(749): Symfony\\Component\\HttpFoundation\\Response->__construct(Object(Illuminate\\View\\View), 200, Array) #8 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(721): Illuminate\\Routing\\Router::toResponse(Object(Illuminate\\Http\\Request), Object(Illuminate\\View\\View)) #9 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(681): Illuminate\\Routing\\Router->prepareResponse(Object(Illuminate\\Http\\Request), Object(Illuminate\\View\\View)) #10 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request)) #11 /./vendor/silber/page-cache/src/Middleware/CacheResponse.php(38): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #12 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Silber\\PageCache\\Middleware\\CacheResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #13 /var/www/object/app/Http/Middleware/FacebookSwitch.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #14 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\FacebookSwitch->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #15 /var/www/object/app/Http/Middleware/CheckStoreStatus.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #16 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\CheckStoreStatus->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #17 /var/www/object/app/Http/Middleware/Statistics.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #18 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\Statistics->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #19 /var/www/object/app/Http/Middleware/PasswordProtected.php(66): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #20 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\PasswordProtected->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #21 /var/www/object/app/Http/Middleware/DetectLanguage.php(25): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #22 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\DetectLanguage->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #23 /var/www/object/app/Http/Middleware/ConfigTheme.php(101): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #24 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\ConfigTheme->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #25 /./vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #26 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #27 /var/www/object/app/Http/Middleware/SwitchDomain.php(34): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #28 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\SwitchDomain->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #29 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #30 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #31 /./vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #32 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #33 /./vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(56): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #34 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #35 /./vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #36 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #37 /./vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #38 /var/www/object/app/Http/Middleware/EncryptCookies.php(29): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #39 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #40 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #41 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(683): Illuminate\\Pipeline\\Pipeline->then(Object(Closure)) #42 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(658): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request)) #43 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(624): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route)) #44 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(613): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request)) #45 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(170): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request)) #46 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request)) #47 /./vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(60): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #48 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #49 /var/www/object/app/Http/Middleware/ChangeAppUrlMiddleware.php(23): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #50 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\ChangeAppUrlMiddleware->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #51 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #52 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #53 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #54 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #55 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #56 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #57 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(63): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #58 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #59 /./vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #60 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #61 /./vendor/dingo/api/src/Http/Middleware/Request.php(111): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #62 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #63 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #64 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(145): Illuminate\\Pipeline\\Pipeline->then(Object(Closure)) #65 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request)) #66 /var/www/object/public/index.php(57): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request)) #67 {main} [previous exception] [object] (RuntimeException(code: 0): Invalid json: { \"sections\": { \"3collection_s7mzoitr\": { \"type\": \"main-collections\", \"settings\": { \"heading\": \"\\GráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트\" }, }, } } : Syntax error at /var/www/object/Modules/ThemeSetting/Util/JsonDecoder.php:18) [stacktrace] #0 /var/www/object/Modules/ThemeSetting/View/ManagesTemplate.php(43): Modules\\ThemeSetting\\Util\\JsonDecoder::jsonToArray('{\ \"sections\":...') #1 /./vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php(114): Illuminate\\View\\Factory->Modules\\ThemeSetting\\View\\{closure}() #2 /var/www/object/storage/framework/views/8770ac3ae62f52f71ff8e3e1b63e49e7e9ce5ac3.php(222): Illuminate\\View\\Factory->__call('renderObjectSect...', Array) #3 /./vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(43): include('/var/www/object/...') #4 /./vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\\View\\Engines\\PhpEngine->evaluatePath('/var/www/object/...', Array) #5 /./vendor/laravel/framework/src/Illuminate/View/View.php(143): Illuminate\\View\\Engines\\CompilerEngine->get('/var/www/object/...', Array) #6 /./vendor/laravel/framework/src/Illuminate/View/View.php(126): Illuminate\\View\\View->getContents() #7 /./vendor/laravel/framework/src/Illuminate/View/View.php(91): Illuminate\\View\\View->renderContents() #8 /./vendor/laravel/framework/src/Illuminate/Http/Response.php(42): Illuminate\\View\\View->render() #9 /./vendor/symfony/http-foundation/Response.php(205): Illuminate\\Http\\Response->setContent(Object(Illuminate\\View\\View)) #10 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(749): Symfony\\Component\\HttpFoundation\\Response->__construct(Object(Illuminate\\View\\View), 200, Array) #11 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(721): Illuminate\\Routing\\Router::toResponse(Object(Illuminate\\Http\\Request), Object(Illuminate\\View\\View)) #12 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(681): Illuminate\\Routing\\Router->prepareResponse(Object(Illuminate\\Http\\Request), Object(Illuminate\\View\\View)) #13 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request)) #14 /./vendor/silber/page-cache/src/Middleware/CacheResponse.php(38): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #15 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Silber\\PageCache\\Middleware\\CacheResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #16 /var/www/object/app/Http/Middleware/FacebookSwitch.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #17 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\FacebookSwitch->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #18 /var/www/object/app/Http/Middleware/CheckStoreStatus.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #19 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\CheckStoreStatus->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #20 /var/www/object/app/Http/Middleware/Statistics.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #21 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\Statistics->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #22 /var/www/object/app/Http/Middleware/PasswordProtected.php(66): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #23 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\PasswordProtected->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #24 /var/www/object/app/Http/Middleware/DetectLanguage.php(25): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #25 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\DetectLanguage->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #26 /var/www/object/app/Http/Middleware/ConfigTheme.php(101): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #27 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\ConfigTheme->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #28 /./vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #29 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #30 /var/www/object/app/Http/Middleware/SwitchDomain.php(34): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #31 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\SwitchDomain->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #32 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #33 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #34 /./vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #35 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #36 /./vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(56): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #37 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #38 /./vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #39 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #40 /./vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #41 /var/www/object/app/Http/Middleware/EncryptCookies.php(29): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #42 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #43 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #44 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(683): Illuminate\\Pipeline\\Pipeline->then(Object(Closure)) #45 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(658): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request)) #46 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(624): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route)) #47 /./vendor/laravel/framework/src/Illuminate/Routing/Router.php(613): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request)) #48 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(170): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request)) #49 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request)) #50 /./vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(60): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #51 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Barryvdh\\Debugbar\\Middleware\\InjectDebugbar->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #52 /var/www/object/app/Http/Middleware/ChangeAppUrlMiddleware.php(23): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #53 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): App\\Http\\Middleware\\ChangeAppUrlMiddleware->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #54 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #55 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #56 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #57 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #58 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #59 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #60 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(63): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #61 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #62 /./vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #63 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #64 /./vendor/dingo/api/src/Http/Middleware/Request.php(111): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #65 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(171): Dingo\\Api\\Http\\Middleware\\Request->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #66 /./vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #67 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(145): Illuminate\\Pipeline\\Pipeline->then(Object(Closure)) #68 /./vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request)) #69 /var/www/object/public/index.php(57): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request)) #70 {main} "}
3、初步怀疑应该与:\ 有关系,当在请求参数中删除输入:\ 后,渲染模板响应 200。如图3
4、决定在测试环境中打印待解析的 JSON 字符串。发现虽然输入的是 \,但是请求参数上已经变化为:\\,解析的时候又已经是:\,进而导致解析错误。如图4
{ "sections": { "3collection_s7mzoitr": { "type": "main-collections", "settings": { "heading": "\GráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트Top CategoriesTamañoTableauTaillesGrößentabelleGráサイズチャートТаблица РазмеровMaattabel사이즈 차트TamañoGrößentabelleGráa toサТаблица 차트" }, "blocks": { "collection-0": { "type": "collection", "settings": { "id": 119 } } } } } }
5、应该在调用解析 JSON 之前,仍然保留 \\ 才是。但是现阶段的业务逻辑是,在接收到 JSON 之后,先存储至缓存中(此时已经变化为 \),然后从缓存中取出 JSON 放至模板文件中,再执行 JSON 的解析。查看报错的模板文件。如图5
<?php if($section['type'] === 'collection'): ?> "<?php echo e($id); ?>": { "type": "main-collections", "settings": { "heading": "<?php echo e($section['title']); ?>" }, "blocks": { <?php $__currentLoopData = $section['ids']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> "collection-<?php echo e($key); ?>": { "type": "collection", "settings": { "id": <?php echo e($item); ?> } }<?php if(!$loop->last): ?>,<?php endif; ?> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> } }, <?php endif; ?>
6、编辑原始的模板文件,基于字符串函数 addslashes() 自动转义。渲染模板不再报错。符合预期。如图6
@if($section['type'] === 'collection') "{{ $id }}": { "type": "main-collections", "settings": { "heading": "{{ addslashes($section['title']) }}" }, "blocks": { @foreach ($section['ids'] as $key => $item) "collection-{{ $key }}": { "type": "collection", "settings": { "id": {{ $item }} } }@if (!$loop->last),@endif @endforeach } }, @endif
7、但是,在输入 ‘、”” 字符时,响应 500。解析失败。如图7
8、查看渲染后的 PHP 模板代码 ,e(addslashes($section[‘title’]))
<?php if($section['type'] === 'collection'): ?> "<?php echo e($id); ?>": { "type": "main-collections", "settings": { "heading": "<?php echo e(addslashes($section['title'])); ?>" }, "blocks": { <?php $__currentLoopData = $section['ids']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> "collection-<?php echo e($key); ?>": { "type": "collection", "settings": { "id": <?php echo e($item); ?> } }<?php if(!$loop->last): ?>,<?php endif; ?> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> } }, <?php endif; ?>
9、原以为的 \’ 被转换为:\"
10、决定修改 Blade 模板源代码,使用 {!! !!},防止第 9 步骤的出现
{!! addslashes($section['title']) !!}
11、在输入 ‘ 字符时,虽然格式已经变化为:\’,响应 500。解析失败。如图8
12、最终决定仅转义 \,基于 addcslashes — 以 C 语言风格使用反斜线转义字符串中的字符
{!! addcslashes($section['title'], '\\') !!}
13、请求参数:’,’ 已经解析成功。如图9
14、在输入 ” 字符时,请求参数:\”,” 已经解析失败。如图10
15、此时,JSON 的转义应该与前端保持一致,转义 \ 与 ”
{!! addcslashes($section['title'], '\\"') !!}
16、在输入 ” 字符时,请求参数:\”,\” 已经解析成功。如图11
17、测试一下 js 代码的输入,未执行 js 脚本,因为 JSON 格式仅用于解析,在渲染模板时,仍然会经过 PHP 的 htmlspecialchars 函数传递来防范 XSS 攻击的。如图12
<script> alert("Hello! I am an alert box!"); </script>
18、以下字符是保留字符,不能在 JSON 中使用,必须正确转义才能在字符串中使用。除 ” 或 \ 或控制字符外的任何字符。参考网址:https://www.json.org/json-zh.html 。如果在富文本中接收前端输入的数据,则以下字符皆需要转义。如图13
Backspace to be replaced with \b Form feed to be replaced with \f Newline to be replaced with \n Carriage return to be replaced with \r Tab to be replaced with \t quotation mark \" Backslash to be replaced with \\
19、在输入换行字符时,请求参数:\n,\n 已经解析失败。如图14
{ "heading": "\\\"' IMAGE WITH TEXT1" }
{!! addcslashes($section['horizontal']['title'], '\n\\"') !!}
20、调整 addcslashes 的 charlist 参数,使用 “” 包含。解析成功。如图15
{!! addcslashes($section['horizontal']['title'], '\n\\"') !!}
20、您通常不必在以编程方式生成 JSON 时自己考虑转义字符(当然,在手动编辑例如基于 JSON 的配置文件时您会考虑)。相反,使用您的语言具有的任何本机映射、数组、字符串、数字、布尔值和空类型来形成您想要编码的数据结构,然后使用 JSON 编码函数将其编码为 JSON。这样的函数可能内置在您使用的任何语言中,例如 JavaScript 的 JSON.stringify、PHP 的 json_encode。现在确定是在模板文件中手动编辑基于 JSON 的配置文件。
21、不过 \b 会替换掉值中的 b
<?php $title = <<<HTML <div><span>abfnrt 中国人人要 uc"\/</span>4</div> HTML; echo "$title\n\n\n"; $json = '{"title": "' . addcslashes($title, "\b\f\n\r\t\\\"") . '"}'; // echo $json; $obj = json_decode($json); // var_dump($obj); echo $obj->{'title'}; ?>
<div><span>abfnrt 中国人人要 uc"\/</span>4</div> <div><span>afnrt 中国人人要 uc"\/</span>4</div>
22、不过 \u 会导致解析失败
<?php $title = <<<HTML <div><span>abfnrt 中国人人要 uc"\/</span>4</div> HTML; echo "$title\n\n\n"; $json = '{"title": "' . addcslashes($title, "\b\f\n\r\t\u\\\"") . '"}'; // echo $json; $obj = json_decode($json); // var_dump($obj); echo $obj->{'title'}; ?>
<div><span>abfnrt 中国人人要 uc"\/</span>4</div> <br /> <b>Notice</b>: Trying to get property 'title' of non-object in <b>E:\wwwroot\addcslashes.php</b> on line <b>19</b><br />
23、最终的演示示例,输出符合预期。如图16
<?php $title = <<<HTML <div><span>abfnrt 中国人人要 uc"\/</span>4</div> HTML; echo "$title\n\n\n"; $json = '{"title": "' . addcslashes($title, "\f\n\r\t\\\"") . '"}'; // echo $json; $obj = json_decode($json); // var_dump($obj); echo $obj->{'title'}; ?>
<div><span>abfnrt 中国人人要 uc"\/</span>4</div> <div><span>abfnrt 中国人人要 uc"\/</span>4</div>
近期评论