Skip to content

toString() might be broken sometimes #58

Closed

Description

@wiwichips

I was testing PythonMonkey with the CryptoJS NPM package and noticed calling toString() on the objects returned from it would yield empty strings. Refer to this example to reproduce it:


In Python:

(Pdb) CryptoJS.SHA256("hello").toString()
''

^ when ran in Python, it just returns an empty string

In JavaScript

> CryptoJS.SHA256("hello").toString()
'2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'

@wesgarland suggested "we're probably calling toString on the wrong this"

Activity

  1. wesgarland commented on Jul 14, 2023

    @wesgarland
    Collaborator

    @wiwichips Would you might retesting against today's tip?

  2. wiwichips commented on Jul 19, 2023

    @wiwichips
    CollaboratorAuthor

    @wiwichips Would you might retesting against today's tip?
    I don't remember what the tip was

    For what its worth I am still seeing this behaviour on newest PythonMonkey pull on main:

    package.json

    {
      "dependencies": {
        "crypto-js": "^4.1.1"
      }
    }

    main.py

    import pythonmonkey as pm
    CryptoJS = pm.require('crypto-js')
    cipher = CryptoJS.SHA256("Hello, World!").toString(() 
    print(cipher) # ''

    It prints the empty string, but it should print dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f


    If I call toString() in JavaScript code and call that JavaScript code from Python it works as expected. So for examples like this I do something like this:

    sha256.js

    const CryptoJS = require("crypto-js");
    
    module.exports = function sha256(thing) {
      return CryptoJS.SHA256(thing).toString()
    }

    main.py

    import pythonmonkey as pm
    
    sha256 = pm.require("./sha256")
    
    print(sha256("Hello, World!")) # this outputs dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f
  3. philippedistributive commented on Jan 29, 2024

    @philippedistributive
    Contributor

    Repro should be
    $ npm install crypto-js
    $ touch main.js
    main.js:
    import pythonmonkey as pm
    CryptoJS = pm.require('crypto-js')
    cipher = CryptoJS.SHA256("Hello, World!").toString()
    print(cipher) # ''

  4. linked a pull request that will close this issueCaleb/fix/this #227on Feb 6, 2024
  5. added a commit that references this issue on Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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