Skip to content

Mismatch between CLI and JS usage due to echo #32

@alexandercerutti

Description

@alexandercerutti

I was using this library via CLI to generate some mock IDs that should match actual IDs generated through our code, that uses NPM integrated.

By following the examples in the README, I did something like this:

echo 'site1.com/podc_article1' | pnpm base32
# OUTCOME: edmq8t9h5thpyv9fe1qp8ruzc5t78ub3dhjk22g

(yes, I'm using pnpm and a monorepo, so the only way to reach base32 without installing it globally, is this one).

However, when I run the same string in the JS code directly, without passing through the CLI, I get a sightly different ID:

base32.encode("site1.com/podc_article1")
// Outcome: edmq8t9h5thpyv9fe1qp8ruzc5t78ub3dhjk2

By using the CLI to decode both IDS, the string matches correctly:

echo 'edmq8t9h5thpyv9fe1qp8ruzc5t78ub3dhjk2' | pnpm base32 -d
echo 'edmq8t9h5thpyv9fe1qp8ruzc5t78ub3dhjk22g' | pnpm base32 -d

# Outcome: site1.com/podc_article1

I was remembering there were some kind of weird behaviors with echo, and a short research confirmed to me: echo prints an additional EOL character.

So, I tried using printf and the output became coherent with the usage via JS.

Checking the examples in the readme, ofc, do the same:

echo "Hello World" | pnpm base32
#> 91jprv3f41bpywkccg50

printf "Hello World" | pnpm base32
#> 91jprv3f41bpywkccg

I'm not sure this is something that can or should be fixed in either the library OR the bin file.
However, this thing caused me an issue, as the id I was generating, were for a NOSQL DB and I was performing the tests. It made me go crazy.

@agnoster can I help in any way with this? I was thinking of editing the README in the meantime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions