You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we call the embed function on a json report (using --format json -o <report_name>), the base64 encoded string doesn't render the image if we try to embed it in an HTML report. I have done a bit of digging and it seems that the "offending" line is the following:
File.read(filename)
(since json class inherits from gherkin_formatter_adapter)
in lib/cucumber/formatter/gherkin_formatter_adapter.rb
I have proven it using the following test script:
require'base64'filename='myimage.png'#generates a proper image in windows#file_content = File.open(filename, 'rb') { |f| f.read }#generates a broken image in windowsfile_content=File.read(filename)encoded_data=Base64.encode64(file_content).gsub("\n",'')File.open('decoded.png','wb')do|f|
f.write(Base64.decode64(encoded_data))endhtml_content=%Q"<html><img src='data:image/png;base64,#{encoded_data}'/></html>"File.open('base64.html','w')do|f|
f.write(html_content)end
Both 'decoded.png' and the html output will not show the image. However, when i replace the file.read function with file_content = File.open(filename, 'rb') { |f| f.read }, the image and html file will render the image properly.
I think it has to do with windows not being able to interpret the image as a binary by default when it uses the File.read function. I've tested the script under macox, windows (with both ruby 1.8.7 and 1.9.3). Under macosx, either method of reading renders a proper image, but not in windows
The text was updated successfully, but these errors were encountered:
it looks like we just need to force GherkinFormatterAdapter.embed() read file in binary mode (for 1.9 it would be just adding 'rb' as a second param, but for 1.8.7 we have to use File.open(filename, 'rb') { |f| f.read })
Hi,
When we call the embed function on a json report (using --format json -o <report_name>), the base64 encoded string doesn't render the image if we try to embed it in an HTML report. I have done a bit of digging and it seems that the "offending" line is the following:
File.read(filename)
(since json class inherits from gherkin_formatter_adapter)
in lib/cucumber/formatter/gherkin_formatter_adapter.rb
I have proven it using the following test script:
Both 'decoded.png' and the html output will not show the image. However, when i replace the file.read function with file_content = File.open(filename, 'rb') { |f| f.read }, the image and html file will render the image properly.
I think it has to do with windows not being able to interpret the image as a binary by default when it uses the File.read function. I've tested the script under macox, windows (with both ruby 1.8.7 and 1.9.3). Under macosx, either method of reading renders a proper image, but not in windows
The text was updated successfully, but these errors were encountered: