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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with stdin and empty strings using Node.js #4258

Closed
jsbass opened this issue Oct 26, 2023 · 2 comments 路 Fixed by #4327
Closed

Issue with stdin and empty strings using Node.js #4258

jsbass opened this issue Oct 26, 2023 · 2 comments 路 Fixed by #4327
Labels
bug Something isn't working
Milestone

Comments

@jsbass
Copy link

jsbass commented Oct 26, 2023

馃悰 Bug

This bug only occurs in the NPM version. I can't replicate this in a browser.
When using a custom stdin callback, if an empty string is returned, an EOFError is thrown. An empty string seems to be acting the same as null or undefined. I tried changing autoEOF to false but that didn't have an effect.

To Reproduce

Make a new node project and put the following code in the the index.js

const { loadPyodide } = require("pyodide");

const testStdin = async (arr) => {
    const py = await loadPyodide();
    let idx = 0;
    py.setStdin({
        stdin: () => {
            return arr[idx++];
        }
    });
    py.runPython(`
        a = input()
        b = input()
        c = input()
        print(a)
        print(b)
        print(c)
    `);
}

testStdin(['asdf', 'qwer', '']).then(console.log).catch(console.error)
  • An EOFError is thrown

This code works correctly if the last item in the array is not empty

Expected behavior

Expected to see the value of c be assigned ""

Environment

  • Pyodide Version: 0.24.0
  • Node version: 20.5.0
  • Any other relevant information:

Additional context

@jsbass jsbass added the bug Something isn't working label Oct 26, 2023
@ryanking13
Copy link
Member

Thanks for the report! I was able to reproduce it in our latest console in our chrome browser:

image

@ryanking13
Copy link
Member

pyodide/src/js/streams.ts

Lines 570 to 572 in 9c498a8

if (!val) {
return undefined;
}

The problem seems to be here, where undefined is returned because the empty string is a falsy value. @hoodmane What would be the intended behavior here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants