Skip to content

Commit

Permalink
Merge branch 'fixFilenameEncoding-604' into 'main'
Browse files Browse the repository at this point in the history
Fixes enconding of filename when adding a dataset file

See merge request softwares-pkp/plugins_ojs/dataverse!148
  • Loading branch information
thiagolepidus committed Oct 25, 2023
2 parents ca732b1 + 206f78e commit 3e71424
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
9 changes: 9 additions & 0 deletions classes/factories/JsonDatasetFactory.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ protected function sanitizeProps(): array
$datasetFile->setId($file->dataFile->id);
$datasetFile->setFileName($file->label);
$datasetFile->setOriginalFileName($file->dataFile->filename);

$encodedChar = 'Ã';
if (str_contains($file->label, $encodedChar)) {
$datasetFile->setFileName(utf8_decode($file->label));
}
if (str_contains($file->dataFile->filename, $encodedChar)) {
$datasetFile->setOriginalFileName(utf8_decode($file->dataFile->filename));
}

return $datasetFile;
}, $datasetVersion->files);

Expand Down
15 changes: 8 additions & 7 deletions cypress/tests/Test03_ResearchDataDeposit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,22 @@ describe('Research data deposit', function () {
cy.fixture('dummy.pdf', 'base64').then((fileContent) => {
cy.get('#datasetFileForm-datasetFile-hiddenFileId').upload({
fileContent,
fileName: 'samples.pdf',
fileName: 'Submissão de dados.pdf',
mimeType: 'application/pdf',
encoding: 'base64',
});
});
cy.get('input[name="termsOfUse"').check();
cy.get('form:visible button:contains("Save")').click();
cy.waitJQuery();
cy.get('#datasetFiles .listPanel__items').contains('samples.pdf');
cy.get('#datasetFiles .listPanel__items').contains('Submissão de dados.pdf');
cy.get('#datasetTab-button .pkpBadge').contains('2');

cy.get('.listPanel__item:contains(samples.pdf) button:contains(Delete)').click();
cy.get('#datasetFiles .listPanel__items').contains('samples.pdf');
cy.get('.listPanel__item:contains(Submissão de dados.pdf) button:contains(Delete)').click();
cy.get('#datasetFiles .listPanel__items').contains('Submissão de dados.pdf');
cy.get('.modal:visible button:contains(Yes)').click();
cy.waitJQuery();
cy.get('#datasetFiles .listPanel__items').should('not.include.text', 'samples.pdf');
cy.get('#datasetFiles .listPanel__items').should('not.include.text', 'Submissão de dados.pdf');
cy.get('#datasetTab-button .pkpBadge').contains('1');
});

Expand All @@ -221,8 +221,8 @@ describe('Research data deposit', function () {
cy.contains('Activity Log').click();
cy.get('#submissionHistoryGridContainer tr:contains(Research data deposited) td').should('contain', 'Catherine Kwantes');
cy.get('#submissionHistoryGridContainer tr:contains(Research data metadata updated) td').should('contain', 'Catherine Kwantes');
cy.get('#submissionHistoryGridContainer tr:contains(File "samples.pdf" added as research data.) td').should('contain', 'Catherine Kwantes');
cy.get('#submissionHistoryGridContainer tr:contains(File "samples.pdf" deleted from research data.) td').should('contain', 'Catherine Kwantes');
cy.get('#submissionHistoryGridContainer tr:contains(File "Submissão de dados.pdf" added as research data.) td').should('contain', 'Catherine Kwantes');
cy.get('#submissionHistoryGridContainer tr:contains(File "Submissão de dados.pdf" deleted from research data.) td').should('contain', 'Catherine Kwantes');
cy.get('#submissionHistoryGridContainer tr:contains(Research data deleted) td').should('contain', 'Catherine Kwantes');
});

Expand Down Expand Up @@ -500,6 +500,7 @@ describe('Research data deposit', function () {
+ dataverseServerName;
cy.get('div[data-modal="publish"]').contains(publishMsg);
cy.get('div[data-modal="publish"] button').contains('Yes').click();
cy.wait(1000);

cy.get('.value > p').contains('V1');
cy.get('button').contains('Publish research data').should('not.exist');
Expand Down
15 changes: 14 additions & 1 deletion dataverseAPI/actions/DatasetFileActions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ public function getByDatasetId(string $persistentId): array
$datasetFile->setId($file['dataFile']['id']);
$datasetFile->setFileName($file['label']);
$datasetFile->setOriginalFileName($file['dataFile']['filename']);

$encodedChar = 'Ã';
if (str_contains($file['label'], $encodedChar)) {
$datasetFile->setFileName(utf8_decode($file['label']));
}
if (str_contains($file['dataFile']['filename'], $encodedChar)) {
$datasetFile->setOriginalFileName(utf8_decode($file['dataFile']['filename']));
}

return $datasetFile;
}, $jsonContent['data']);
}
Expand All @@ -35,8 +44,12 @@ public function add(string $persistentId, string $filename, string $filePath): v
'name' => 'file',
'contents' => Utils::tryFopen($filePath, 'rb'),
'filename' => $filename
],
[
'name' => 'jsonData',
'contents' => json_encode(['label' => $filename])
]
]
],
];

$this->nativeAPIRequest('POST', $uri, $options);
Expand Down
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<version>
<application>dataverse</application>
<type>plugins.generic</type>
<release>2.5.6.0</release>
<date>2023-10-19</date>
<release>2.5.7.0</release>
<date>2023-10-25</date>
<lazy-load>1</lazy-load>
<class>DataversePlugin</class>
</version>

0 comments on commit 3e71424

Please sign in to comment.