Skip to content

fix: btoa error #114

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

Merged
merged 3 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ Cypress.Commands.add(
if (res.error) {
log.set(
"message",
`${res.message}\n[See comparison](${LINK_PREFIX}${btoa(
JSON.stringify({ title, imgPath })
)})`
`${res.message}\n[See comparison](${LINK_PREFIX}${btoa(unescape(encodeURIComponent(JSON.stringify({
Copy link
Member

Choose a reason for hiding this comment

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

I think we shouldn't use escape/unescape methods as they're described as deprecated.
Is encodeURIComponent not enough to fix this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @FRSgit, thanks also for your attention, I'll look into it further soon.

Copy link
Contributor Author

@iamyoki iamyoki Sep 14, 2022

Choose a reason for hiding this comment

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

Hi @FRSgit, after research, the best way is to implement an escape Base64 by ourself to replace the deprecated escape, btoa methods, so I found this answer and followed it.
https://stackoverflow.com/a/26603875/15495687

Copy link
Member

Choose a reason for hiding this comment

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

@iamyoki Thanks for doing the research - indeed it seems that this is the best approach. Personally I would think about rereleasing the webtoolkit.base64 on npm (the same way webtoolkit.md5 is released) as it's nicer to be able to share this kind of functionalities with other libraries.
But this solution is well enough for now, so I'd say let's stick with it until somebody will be willing to refactor 😄
Thanks again!

title,
imgPath
}))))})`
);
log.set("consoleProps", () => res);
const err = new Error(res.message);
Expand Down
2 changes: 1 addition & 1 deletion src/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ after(() => {
if (!top) return false;

const { title, imgPath } = JSON.parse(
atob(e.currentTarget.getAttribute("href").substring(LINK_PREFIX.length))
decodeURIComponent(escape(atob(e.currentTarget.getAttribute("href").substring(LINK_PREFIX.length))))
);
queueClear();

Expand Down