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

atob decoding failure in recordToHistory #75

Open
btheado opened this issue May 13, 2023 · 0 comments
Open

atob decoding failure in recordToHistory #75

btheado opened this issue May 13, 2023 · 0 comments

Comments

@btheado
Copy link

btheado commented May 13, 2023

This simple url seems to work: https://itty.bitty.site/#/data:text/plain;charset=utf-8,hello%20world. However, I see this exception in the console:

bitty.js:87 Uncaught (in promise) DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at get href [as href] (https://itty.bitty.site/bitty.js:87:27)
    at recordToHistory (https://itty.bitty.site/index.js:501:42)
    at renderContent (https://itty.bitty.site/index.js:412:37)

After stepping through the debugger, it looks to be that durl.href is not a well-behaved getter. It is modifying state (this.dataPrefix):

https://github.com/alcor/itty-bitty/blob/afe37fa0b34610c6f179a9b184a5d0e2a7c836fd/docs/bitty.js#L79-L91

That means the first time the href getter is called, the dataPrefix will be modified to its decoded value:
https://github.com/alcor/itty-bitty/blob/afe37fa0b34610c6f179a9b184a5d0e2a7c836fd/docs/index.js#L388

Then the second time it is called it will fail to decode since it is already decoded:
https://github.com/alcor/itty-bitty/blob/afe37fa0b34610c6f179a9b184a5d0e2a7c836fd/docs/index.js#L412

Maybe the href getter should use a local variable to store the decoded dataPrefix?

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

No branches or pull requests

1 participant