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

Fixes #13919, make response->setFileToSend support non-ASCII filename. #14333

Merged
merged 14 commits into from
Aug 30, 2019
Merged

Fixes #13919, make response->setFileToSend support non-ASCII filename. #14333

merged 14 commits into from
Aug 30, 2019

Conversation

ian4hu
Copy link
Contributor

@ian4hu ian4hu commented Aug 27, 2019

Hello!

In raising this pull request, I confirm the following:

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR
  • I have updated the relevant CHANGELOG
  • I have created a PR for the documentation about this change

Small description of change:
Add non-ASCII support basename() by Phalcon\Helper\Fs and fixed the #13919

Thanks

@ruudboon
Copy link
Member

ruudboon commented Aug 27, 2019

Thank you for the pull. We're not accepting pulls on the master. Can you sent into the 4.0.x branch and would it be possible to add some unit tests?

@ian4hu ian4hu changed the base branch from master to 4.0.x August 27, 2019 10:39
@ian4hu
Copy link
Contributor Author

ian4hu commented Aug 27, 2019

Thank you for the pull. We're not accepting pulls on the master. Can you sent into the 4.0.x branch and would it be possible to add some unit tests?

I am not sure about how to make a right unit test, because the it only affect the response header.
The Phalcon\Helper\Fs->basename could be unit tested, and I will try to make the unit tests.

phalcon/Helper/Fs.zep Outdated Show resolved Hide resolved
phalcon/Helper/Fs.zep Outdated Show resolved Hide resolved
phalcon/Helper/Fs.zep Outdated Show resolved Hide resolved
phalcon/Http/Response.zep Outdated Show resolved Hide resolved
phalcon/Http/Response.zep Outdated Show resolved Hide resolved
Apply sugguestion

Co-Authored-By: Serghei Iakovlev <sergeyklay@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Aug 27, 2019

Codecov Report

Merging #14333 into 4.0.x will decrease coverage by <.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##            4.0.x   #14333      +/-   ##
==========================================
- Coverage   66.31%   66.31%   -0.01%     
==========================================
  Files         488      488              
  Lines      115910   115927      +17     
==========================================
+ Hits        76862    76873      +11     
- Misses      39048    39054       +6

ian4hu and others added 4 commits August 27, 2019 19:30
Apply sugguestion

Co-Authored-By: Serghei Iakovlev <sergeyklay@users.noreply.github.com>
apply sugguestion

Co-Authored-By: Serghei Iakovlev <sergeyklay@users.noreply.github.com>
Copy link
Member

@ruudboon ruudboon left a comment

Choose a reason for hiding this comment

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

Can you run phpcs to fix the code style? See failing test
https://travis-ci.org/phalcon/cphalcon/jobs/577361625

@ian4hu
Copy link
Contributor Author

ian4hu commented Aug 27, 2019

Can you run phpcs to fix the code style? See failing test
https://travis-ci.org/phalcon/cphalcon/jobs/577361625

sorry for the code style issue. I don't have a fullly configured develop environment and missed the code style check.

@StudioMaX
Copy link
Contributor

Take note that the semicolon at the end of the header is still not allowed according to http://test.greenbytes.de/tech/tc2231/#attwithasciifilenamenqs.

The trailing semicolon makes the header field value syntactically incorrect, as no other parameter follows. Thus the header field should be ignored.

ian4hu added 2 commits August 30, 2019 15:21
The trailing semicolon makes the header field value syntactically incorrect, as no other parameter follows. Thus the header field should be ignored. from: @StudioMaX
@StudioMaX
Copy link
Contributor

StudioMaX commented Aug 30, 2019

@ian4hu could you test these changes with the all common browsers with ASCII/non-ASCII filenames?

I may be wrong, but the file name should still be in double quotes, as the file name may contain spaces (see http://test.greenbytes.de/tech/tc2231/#attwithasciifilenamenqws).

Also, filename in filename= shouldn't be urlencoded, but filename*=UTF-8'' should (see http://test.greenbytes.de/tech/tc2231/#attwithfnrawpctenca).

Maybe something like this:

if basePathEncoding != "ASCII" {
    this->setRawHeader("Content-Disposition: attachment; filename=\"" . basePath . "\"; filename*=". strtolower(basePathEncoding) . "''" . basePathEncoded);
} else {
    this->setRawHeader("Content-Disposition: attachment; filename=\"" . basePath . "\"");
}

@sergeyklay sergeyklay merged commit 8e4643e into phalcon:4.0.x Aug 30, 2019
@sergeyklay
Copy link
Contributor

Thank you

@ian4hu
Copy link
Contributor Author

ian4hu commented Aug 31, 2019

@ian4hu could you test these changes with the all common browsers with ASCII/non-ASCII filenames?

I may be wrong, but the file name should still be in double quotes, as the file name may contain spaces (see http://test.greenbytes.de/tech/tc2231/#attwithasciifilenamenqws).

Also, filename in filename= shouldn't be urlencoded, but filename*=UTF-8'' should (see http://test.greenbytes.de/tech/tc2231/#attwithfnrawpctenca).

Maybe something like this:

if basePathEncoding != "ASCII" {
    this->setRawHeader("Content-Disposition: attachment; filename=\"" . basePath . "\"; filename*=". strtolower(basePathEncoding) . "''" . basePathEncoded);
} else {
    this->setRawHeader("Content-Disposition: attachment; filename=\"" . basePath . "\"");
}

I could not make a complete tests in http://test.greenbytes.de/tech/tc2231/#attwithasciifilenamenqws, I only have the main stream browser sets to test, which including latest Chrome, Firefox, Safari, IE or Edge, and because I am busy at work recently, I don't have time to test so I just make the header to follow RFC2231#Section 5.

IMO, the RFC is the standard specific between browser and server. if I make the framework with browser specific behavior, then if the browser changed its behavior your framework may not work with it again.

@ian4hu ian4hu deleted the bugfix/issue-13919 branch August 31, 2019 02:24
@ian4hu
Copy link
Contributor Author

ian4hu commented Aug 31, 2019

@ian4hu could you test these changes with the all common browsers with ASCII/non-ASCII filenames?

I may be wrong, but the file name should still be in double quotes, as the file name may contain spaces (see http://test.greenbytes.de/tech/tc2231/#attwithasciifilenamenqws).

Also, filename in filename= shouldn't be urlencoded, but filename*=UTF-8'' should (see http://test.greenbytes.de/tech/tc2231/#attwithfnrawpctenca).

Maybe something like this:

if basePathEncoding != "ASCII" {
    this->setRawHeader("Content-Disposition: attachment; filename=\"" . basePath . "\"; filename*=". strtolower(basePathEncoding) . "''" . basePathEncoded);
} else {
    this->setRawHeader("Content-Disposition: attachment; filename=\"" . basePath . "\"");
}

Your suggesstion about quoting is right. as the RFC mentioned:
image

I will re-read the RFC and make some changes later. thanks.

@ian4hu ian4hu mentioned this pull request Sep 1, 2019
5 tasks
@niden niden added the 4.0 label Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants