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

infinite loop protection #298

Open
1 task done
danielroe opened this issue May 22, 2024 · 2 comments
Open
1 task done

infinite loop protection #298

danielroe opened this issue May 22, 2024 · 2 comments

Comments

@danielroe
Copy link
Member

Describe the feature

Discovered in nuxt/nuxt#27130, it's possible to create an infinite loop when getters call console.log, which is true for Vue.

Reproduction: https://codepen.io/danielroe/pen/GRaqZOj?editors=1111

import { consola } from "consola"

consola.wrapConsole()

const scaryObject = {
  get value () {
    console.warn('Do not access me!', scaryObject)
  }
}

consola.log(scaryObject)

I wonder if it would be worth trying to add protection against this kind of thing? Maybe JSON.stringify could be called lazily?

Additional information

  • Would you be willing to help implement this feature?
@pi0
Copy link
Member

pi0 commented May 22, 2024

Util.format handles the recursive structures (but it is only for Node reporters) just to confirm you happened to have this issue with a testing/browser env right?

@danielroe
Copy link
Member Author

danielroe commented May 22, 2024

Yes, this was in a browser env - however I could also reproduce with this code in the Node REPL:

const { consola } = require('consola')

consola.wrapConsole()

const scaryObject = {
  get value () {
    console.warn('Do not access me!', scaryObject)
  }
}

consola.log(scaryObject)

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

2 participants