Skip to content

Commit

Permalink
Fix parsing of empty content-disposition filename subfield
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Mar 14, 2018
1 parent 5329b99 commit 897207f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
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

0 comments on commit 897207f

Please sign in to comment.