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

Fix parsing of empty content-disposition filename subfield #90

Merged
merged 1 commit into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ldp/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def content_disposition_filename
def content_disposition_attributes
parts = headers['Content-Disposition'].split(/;\s*/).collect { |entry| entry.split(/\s*=\s*/) }
entries = parts.collect do |part|
value = part[1].respond_to?(:sub) ? part[1].sub(%r{^"(.+)"$}, '\1') : part[1]
value = part[1].respond_to?(:sub) ? part[1].sub(%r{^"(.*)"$}, '\1') : part[1]
[part[0], value]
end
Hash[entries]
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/ldp/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@
{ 'Content-Disposition' => 'filename="xyz.txt";' },
{ 'Content-Disposition' => 'attachment; filename=xyz.txt' },
{ 'Content-Disposition' => 'attachment; filename="xyz.txt"; size="12345"' },
{ 'Content-Disposition' => 'attachment; filename=""; size="12345"' },
)
end

it 'provides the filename from the content disposition header' do
3.times { expect(subject.content_disposition_filename).to eq 'xyz.txt' }
expect(subject.content_disposition_filename).to eq ''
end
end
end