Skip to content

Commit bd8f445

Browse files
Remove the yml extension from field_apidoc_file_link and field_apidoc_spec allowed values - 3.x branch (#176)
* v3.x-Removed the yml extension from field_apidoc_file_link and field_apidoc_spec allowed values
1 parent 2413717 commit bd8f445

6 files changed

+37
-7
lines changed

apigee_api_catalog.install

+7
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,10 @@ function apigee_api_catalog_update_8808() {
148148
function apigee_api_catalog_update_8809() {
149149
return \Drupal::service('apigee_api_catalog.updates')->update8809();
150150
}
151+
152+
/**
153+
* Removed yml extension from field_apidoc_file_link and field_apidoc_spec allowed values.
154+
*/
155+
function apigee_api_catalog_update_8810() {
156+
return \Drupal::service('apigee_api_catalog.updates')->update8810();
157+
}

config/install/field.field.node.apidoc.field_apidoc_file_link.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ default_value_callback: ''
1919
settings:
2020
link_type: 17
2121
title: 0
22-
file_extensions: 'yml yaml json'
22+
file_extensions: 'yaml json'
2323
no_extension: false
2424
field_type: file_link

config/install/field.field.node.apidoc.field_apidoc_spec.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ default_value: { }
1818
default_value_callback: ''
1919
settings:
2020
file_directory: apidoc_specs
21-
file_extensions: 'yml yaml json'
21+
file_extensions: 'yaml json'
2222
max_filesize: ''
2323
description_field: false
2424
handler: 'default:file'

src/Entity/ApiDoc.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
258258
->setRevisionable(TRUE)
259259
->setSettings([
260260
'file_directory' => 'apidoc_specs',
261-
'file_extensions' => 'yml yaml json',
261+
'file_extensions' => 'yaml json',
262262
'handler' => 'default:file',
263263
'text_processing' => 0,
264264
])
@@ -279,7 +279,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
279279
->setDescription(t('The URL to an OpenAPI file spec.'))
280280
->addConstraint('ApiDocFileLink')
281281
->setSettings([
282-
'file_extensions' => 'yml yaml json',
282+
'file_extensions' => 'yaml json',
283283
'link_type' => LinkItemInterface::LINK_GENERIC,
284284
'title' => DRUPAL_DISABLED,
285285
])

src/UpdateService.php

+23
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,29 @@ public function update8809() {
426426
->save();
427427
}
428428

429+
/**
430+
* Removed .yml file upload for security reasons.
431+
*/
432+
public function update8810() {
433+
$fields = [
434+
'field_apidoc_file_link',
435+
'field_apidoc_spec',
436+
];
437+
438+
foreach ($fields as $field) {
439+
$fieldConfig = FieldConfig::loadByName('node', 'apidoc', $field);
440+
// Only look for yml extension.
441+
$extensions = $fieldConfig->getSetting('file_extensions');
442+
if (strpos($extensions, 'yml') !== FALSE) {
443+
// Remove yml extension from allowed values.
444+
$fieldConfig->setSetting('file_extensions', 'yaml json')
445+
->save();
446+
}
447+
}
448+
449+
return 'Removed the yml extension from field_apidoc_file_link and field_apidoc_spec allowed values for security reasons.';
450+
}
451+
429452
/**
430453
* Get the field map from apidoc fields to node fields.
431454
*

tests/src/Functional/ApiDocsAdminTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public function testApiDocAdministration() {
107107
// Create a new spec in site.
108108
$file = File::create([
109109
'uid' => $this->adminUser->id(),
110-
'filename' => 'specA.yml',
111-
'uri' => 'public://specA.yml',
110+
'filename' => 'specA.yaml',
111+
'uri' => 'public://specA.yaml',
112112
'filemime' => 'application/octet-stream',
113113
'created' => 1,
114114
'changed' => 1,
@@ -146,7 +146,7 @@ public function testApiDocAdministration() {
146146
// Edit form should have proper values.
147147
$assert->fieldValueEquals('title[0][value]', $random_name);
148148
$assert->fieldValueEquals('body[0][value]', $random_description);
149-
$assert->linkExists('specA.yml');
149+
$assert->linkExists('specA.yaml');
150150

151151
// Delete the entity.
152152
$this->clickLink('Delete');

0 commit comments

Comments
 (0)