Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[media] Special characters issue #7386

Merged
merged 11 commits into from
Apr 20, 2021

Conversation

pierre-p-s
Copy link
Contributor

@pierre-p-s pierre-p-s commented Mar 11, 2021

Brief summary of changes

Solves an issue when if using special characters (&, <, >, ") the file download fails and the name of the file appears incorrectly in the browse tab of the media module.
The script removes the special characters from the sql data table media as well as from the file system.

Testing instructions (if applicable)

  1. Before checking out this branch, on 23.0-release, upload a file with special characters &, <, >, " into media.
  2. Check that the file name appears incorrectly in the media table
  3. Check out this branch.
  4. Upload a different file with special characters &, <, >, " into media.
  5. Look for the file in the browse tab, check that the file name appears correctly
  6. Try downloading the file and opening it.
  7. run (need sudo to be able to change the name of the files under /data/media_uploads/): sudo php /var/www/loris/tools/single_use/Cleanup_Special_Chars_Media.php
  8. Check that the first file now appears correctly in the data table and that when downloading you are able to read the file correctly.

@pierre-p-s
Copy link
Contributor Author

The test suite seems to be failing when running make checkstatic however on my VM the command runs without errors.

@pierre-p-s pierre-p-s added the "Help! I don't understand Travis!" PR is having a beef with TRAVIS. Someone needs to help label Mar 11, 2021
@pierre-p-s pierre-p-s added Blocked PR awaiting the merge, resolution or rejection of an other Pull Request and removed "Help! I don't understand Travis!" PR is having a beef with TRAVIS. Someone needs to help labels Mar 15, 2021
@pierre-p-s
Copy link
Contributor Author

Blocked by #7390

@pierre-p-s
Copy link
Contributor Author

After discussion with Rida: Remove encoding when inserting into SQL table, line 186 of fileUpload use unsafe insert and fix issues in the database

@ridz1208 ridz1208 added the Needs Work PR awaiting additional changes by the author or contains issues that the author needs to fix label Mar 18, 2021
@pierre-p-s
Copy link
Contributor Author

@ridz1208 Let me know if this is a better fix please.

@@ -130,6 +130,7 @@ function uploadFile()
checkDateTaken($dateTaken);

$fileName = preg_replace('/\s/', '_', $_FILES["file"]["name"]);
$fileName = str_replace("%22", "\"", $fileName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean you are accepting quotes in the name of the file ? also its a bit clearer if you use '"' in the second argument

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I wanted to include the double quotes because right now we can add a file with it in the name. However we need this check fo it to work. Otherwise I could also send an error through swal refusing the quotes, but in that case what else are we not allowing?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%22 is URI encoding, your $filename is never coming from the URI... I'm not clear on why its being "decoded" (and BTW decoding should be done with urldecode() https://www.php.net/manual/en/function.urldecode.php not manually like this)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to urldecode but I cant find where the fileName is being encoded...

@pierre-p-s pierre-p-s removed Blocked PR awaiting the merge, resolution or rejection of an other Pull Request Needs Work PR awaiting additional changes by the author or contains issues that the author needs to fix labels Mar 23, 2021
@pierre-p-s
Copy link
Contributor Author

This PR still needs a script to change the file names in the sql table as well as in /data/uploads

@pierre-p-s pierre-p-s added the Needs Work PR awaiting additional changes by the author or contains issues that the author needs to fix label Mar 24, 2021
@pierre-p-s pierre-p-s removed the Needs Work PR awaiting additional changes by the author or contains issues that the author needs to fix label Mar 31, 2021
Co-authored-by: Rida Abou-Haidar <ridz1208@users.noreply.github.com>
tools/single_use/Cleanup_Special_Chars_Media.php Outdated Show resolved Hide resolved
tools/single_use/Cleanup_Special_Chars_Media.php Outdated Show resolved Hide resolved
@pierre-p-s pierre-p-s requested a review from jesscall April 1, 2021 01:34
@jesscall jesscall added the Passed Manual Tests PR has undergone proper testing by at least one peer label Apr 12, 2021
@jesscall
Copy link
Contributor

Looks good!

);

// update name in file system
shell_exec("mv " . escapeshellarg($media_path . $fileNameURLencoded) . " " . escapeshellarg($media_path . $fileName));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this just using rename?

https://www.php.net/manual/en/function.rename.php

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed it while reviewing the document_repository PR, but can you change it in that script too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to rename and I will create a new PR for the document repository script and link it here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the doc repo script in this PR: #7428

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@driusan let me know if it needs more changes

driusan pushed a commit that referenced this pull request Apr 20, 2021
@driusan driusan merged commit e7e3650 into aces:23.0-release Apr 20, 2021
@ridz1208 ridz1208 added this to the 23.0.3 milestone Apr 20, 2021
@@ -0,0 +1,54 @@
<?php
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before SQL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed Manual Tests PR has undergone proper testing by at least one peer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants