Allow to remove ansi chars from plain text log

This commit is contained in:
Piotr Sarnacki 2013-01-15 02:27:06 +01:00
parent 70cd6ef092
commit e6899b3ce6
2 changed files with 23 additions and 1 deletions

View File

@ -16,7 +16,15 @@ module Travis::Api::App::Responders
headers['Content-Disposition'] = %(#{disposition}; filename="#{filename}") headers['Content-Disposition'] = %(#{disposition}; filename="#{filename}")
endpoint.content_type 'text/plain' endpoint.content_type 'text/plain'
halt resource.content halt(params[:deansi] ? clear_ansi(resource.content) : resource.content)
end end
private
def clear_ansi(content)
content.gsub(/\r\r/, "\r")
.gsub(/^.*\r(?!$)/, '')
.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/m, '')
end
end end
end end

View File

@ -26,5 +26,19 @@ describe Travis::Api::App::Endpoint::Artifacts do
response.body.should == artifact.content response.body.should == artifact.content
response.headers['Content-Disposition'].should == "attachment; filename=\"#{artifact.id}\"" response.headers['Content-Disposition'].should == "attachment; filename=\"#{artifact.id}\""
end end
describe 'with deansi param' do
let(:content) {
"Fetching (0%)\rFetching (10%)\rFetching (100%)\n\e[32m"
}
let(:artifact) { Factory(:log, :content => content) }
it 'clears ansi escape control characters' do
response = get("/artifacts/#{id}.txt", {'deansi' => true})
response.should be_ok
response.body.should == "Fetching (100%)\n"
end
end
end end
end end