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

Crash in Jsoup.parse when stream = null #2252

Closed
JP95Git opened this issue Dec 24, 2024 · 1 comment
Closed

Crash in Jsoup.parse when stream = null #2252

JP95Git opened this issue Dec 24, 2024 · 1 comment
Labels
fixed An {bug|improvement} that has been {fixed|implemented}
Milestone

Comments

@JP95Git
Copy link

JP95Git commented Dec 24, 2024

I am using jsoup 1.18.3 and noticed a ugly behaviour in comparison to jsoup 1.18.0.

I call jsoup like this:
Document doc = Jsoup.parse(stream, null, "");

It happens that the stream is null. This is detected by another part of my program and jsoup previously accepted the null stream. In org.jsoup.helper.DataUtil.parseInputStream(ControllableInputStream, String, String, Parser) it simply returned new Document(baseUri).

With one of the recent changes you wrap a ControllableInputStream.wrap around the stream object. Therefore the check

if (input == null) // empty body // todo reconsider?
  return new Document(baseUri);

at the top of org.jsoup.helper.DataUtil.parseInputStream(ControllableInputStream, String, String, Parser) will never return a new Document when the stream is null. Instead it crashes when detecting the charset using detectCharset from the null stream. This seems to be wrong.

Since null as a stream is supported (see @nullable in the declaration of parseInputStream, I would add this @nullable to org.jsoup.helper.DataUtil.load(InputStream, String, String) too.

Solution (not tested):
I would return null in ControllableInputStream.wrap if the stream is null.

@jhy jhy closed this as completed in e99c87d Jan 2, 2025
@jhy jhy added this to the 1.19.1 milestone Jan 2, 2025
@jhy jhy added the fixed An {bug|improvement} that has been {fixed|implemented} label Jan 2, 2025
@jhy
Copy link
Owner

jhy commented Jan 2, 2025

Thanks, fixed!

jhy added a commit that referenced this issue Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed An {bug|improvement} that has been {fixed|implemented}
Projects
None yet
Development

No branches or pull requests

2 participants