Skip to content

atob decoding failure in recordToHistory #75

Description

@btheado

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions