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

JRuby unable to create HTML doc if URL arg provided #674

Closed
nirvdrum opened this issue May 8, 2012 · 8 comments
Closed

JRuby unable to create HTML doc if URL arg provided #674

nirvdrum opened this issue May 8, 2012 · 8 comments

Comments

@nirvdrum
Copy link

nirvdrum commented May 8, 2012

If a URL is provided when creating a document, Nokogiri errors out on JRuby:

doc = Nokogiri::HTML(open('http://google.com/').read, 'http://google.com/', nil)
pp doc.errors

=> [#<Nokogiri::XML::SyntaxError: /home/nirvdrum/dev/workspaces/mogotest/http:/google.com (No such file or directory)>]
@nirvdrum
Copy link
Author

nirvdrum commented Jun 4, 2012

I'm confirming that this is still an issue in 1.5.3.

@flavorjones
Copy link
Member

Reproduced using this script:


#! /usr/bin/env ruby

require 'nokogiri'
require 'open-uri'
require 'yaml'

puts Nokogiri::VERSION_INFO.to_yaml
html = open('http://google.com/').read
doc = Nokogiri::HTML html, 'http://google.com/', nil
puts "Doc: #{doc.to_html.inspect}"
puts "Errors: #{doc.errors}"

output for me:


--- 
warnings: []

nokogiri: 1.5.3
ruby: 
  version: 1.8.7
  platform: java
  description: jruby 1.6.5.1 (ruby-1.8.7-p330) (2011-12-27 1bf37c2) (Java HotSpot(TM) 64-Bit Server VM 1.7.0) [linux-amd64-java]
  engine: jruby
  jruby: 1.6.5.1
Doc: ""
Errors: /home/mike/code/oss/nokogiri/http:/google.com (No such file or directory)

@yokolet - any ideas?

@jvshahid
Copy link
Member

The problem is that the url is assumed to be a local file path. I modified the code to use the [URI.create](http://docs.oracle.com/javase/6/docs/api/java/net/URI.html#create(java.lang.String\)) method to parse the url and fall back to the old behavior in case of failure.

@yokolet
Copy link
Member

yokolet commented Jun 11, 2012

@jvshahid's patch looks ok. But, before merging the change, let me clarify this.

@flavorjones
Now, nonet is a default setting. Should this prevent internet connection by "nonet" setting? Only when donet is specified, this example should work?

I still don't understans "nonet" option should prevent what.

@yokolet
Copy link
Member

yokolet commented Jun 11, 2012

OK. I figured out Nokogiri is allowed to connect the Internet in this case with nonet option.

@jvshahid would you give us pull request for this fix as well?

The test case needs a bit tweak when there's not internet connection available. I'll do that after merging pull request.

@jvshahid
Copy link
Member

I created a pull request here

@yokolet
Copy link
Member

yokolet commented Jun 11, 2012

I merged the pull request. Thanks!

@yokolet yokolet closed this as completed Jun 11, 2012
@flavorjones
Copy link
Member

in 1.5.5.rc1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants