Skip to content

Commit 4aa8f5b

Browse files
committed
Fix json validator
1 parent f7e6d79 commit 4aa8f5b

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

app/Tdt/Core/BaseController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ public function handleRequest($uri)
9797

9898
// Check the response type
9999
if ($response instanceof \Illuminate\Http\RedirectResponse) {
100-
101100
// Redirect and that's it
102101
return $response;
103102
} else {
104-
105103
// Make sure cross origin requests are allowed for GET
106104
$response->header('Access-Control-Allow-Origin', '*');
107105
$response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE');

app/Tdt/Core/Definitions/DefinitionController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020
class DefinitionController extends ApiController
2121
{
22-
2322
protected $definition;
2423

2524
public function __construct(DefinitionRepositoryInterface $definition)
@@ -145,7 +144,6 @@ public function get($uri)
145144
Auth::requirePermissions('definition.view');
146145

147146
if (!empty($uri)) {
148-
149147
if (!$this->definition->exists($uri)) {
150148
\App::abort(404, "No resource was found identified with " . $uri);
151149
}

app/Tdt/Core/Repositories/JsonDefinitionRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class JsonDefinitionRepository extends BaseDefinitionRepository implements JsonD
99
{
1010

1111
protected $rules = array(
12-
'uri' => 'json|uri|required',
12+
'uri' => 'json|required',
1313
'description' => 'required',
1414
);
1515

app/Tdt/Core/Validators/CustomValidator.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,17 @@ public function validateJson($attribute, $value, $parameters)
4848
{
4949

5050
try {
51-
52-
$data = json_decode(file_get_contents($value));
51+
$data = [];
52+
53+
if (!filter_var($value, FILTER_VALIDATE_URL) === false) {
54+
$ch = curl_init();
55+
curl_setopt($ch, CURLOPT_URL, $value);
56+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
57+
$data = curl_exec($ch);
58+
curl_close($ch);
59+
} else {
60+
$data =@ file_get_contents($value);
61+
}
5362

5463
if (empty($data)) {
5564
return false;

0 commit comments

Comments
 (0)