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 base64 issue with cucumberjs 10+ #297

Closed
wants to merge 1 commit into from

Conversation

lerhum
Copy link

@lerhum lerhum commented Nov 23, 2023

linked to #298

Describe the bug
In the JSON formatter output of multiple-cucumber-html-reporter, all attachments, including those initially attached as plain text strings, are now Base64 encoded. This uniform encoding approach leads to ambiguity for consumers of the report, as they cannot distinguish whether an attachment was originally a plain text string or a different file format.

To Reproduce
Steps to reproduce the behavior:

just generate a report based on cucumber 10.0.1 with some attachement (json/ text / image)

Expected behavior
The expected behavior was that string attachments would remain as plain text in the JSON formatter output, while other types of attachments would be Base64 encoded. This distinction would enable consumers to easily identify the nature of the attachments without additional processing.

Additional context
To resolve this issue, a decoding mechanism such as atob(embedding.data); should be implemented to correctly decode Base64 attachments before passing them to the report. This would ensure that plain text attachments maintain their original format in the JSON output.

@WasiqB
Copy link
Owner

WasiqB commented Dec 5, 2023

@lerhum , can you please fix the failing test?

@@ -408,6 +408,7 @@ function generateReport(options) {
step.attachments = [];
step.embeddings.forEach((embedding, embeddingIndex) => {
/* istanbul ignore else */
embedding.data = atob(embedding.data);
Copy link

Choose a reason for hiding this comment

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

If we are using atob, we need to escape the Non- ASCII chracters to avoid the Invalid character error.
embedding.data = decodeURIComponent(escape(embedding.data, 'base64'));

But since escape is depericated, try embedding.data = Buffer.from(embedding.data, 'base64') instead

Copy link

Choose a reason for hiding this comment

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

Also, decoding an image/png will break the image in the attachment. Use embedding.data = Buffer.from(embedding.data, 'base64') for any non image/png media type

Copy link

@martdo02 martdo02 left a comment

Choose a reason for hiding this comment

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

Try using embedding.data = Buffer.from(embedding.data, 'base64'); to solve the Invalid character issue

@WasiqB
Copy link
Owner

WasiqB commented Jan 15, 2024

Changes are merged via #308

@WasiqB WasiqB closed this Jan 15, 2024
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.

3 participants