noosfero | 3 new commits pushed to repository
Bráulio Bhavamitra
gitlab at gitlab.com
Mon Feb 23 22:07:37 BRT 2015
Bráulio Bhavamitra pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>
Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/034a99f914e0d064391136be94991ef5232e284d">034a99f9</a> by Braulio Bhavamitra
tiny_mce: remove tests not valid after update
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/965be632fc5c6c09bb213cf0cdeeaacf37f62820">965be632</a> by Braulio Bhavamitra
Drop and replace hpricot with nokogiri
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/ba467618118b5d66472fe40888be435ee1fb62d3">ba467618</a> by Bráulio Bhavamitra
Merge branch 'drop-hpricot' into 'master'
Drop hpricot (unmantained) and replace with nokogiri
One less (old) dependency.
See merge request !366
- - - - -
Changes:
=====================================
Gemfile
=====================================
--- a/Gemfile
+++ b/Gemfile
@@ -11,7 +11,6 @@ gem 'will_paginate', '~> 3.0.3'
gem 'ruby-feedparser', '~> 0.7'
gem 'daemons', '~> 1.1.5'
gem 'thin', '~> 1.3.1'
-gem 'hpricot', '~> 0.8.6'
gem 'nokogiri', '~> 1.5.5'
gem 'rake', :require => false
gem 'rest-client', '~> 1.6.7'
=====================================
INSTALL.md
=====================================
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -21,7 +21,7 @@ Noosfero is written in Ruby with the "[Rails framework](http://www.rubyonrails.o
You need to install some packages Noosfero depends on. On Debian GNU/Linux or Debian-based systems, all of these packages are available through the Debian archive. You can install them with the following command:
# apt-get install ruby rake po4a libgettext-ruby-util libgettext-ruby1.8 \
- libsqlite3-ruby rcov librmagick-ruby libredcloth-ruby libhpricot-ruby \
+ libsqlite3-ruby rcov librmagick-ruby libredcloth-ruby \
libwill-paginate-ruby iso-codes libfeedparser-ruby libdaemons-ruby thin \
tango-icon-theme
@@ -40,7 +40,6 @@ On other systems, they may or may not be available through your regular package
* Daemons - http://daemons.rubyforge.org
* Thin: http://code.macournoyer.com/thin
* tango-icon-theme: http://tango.freedesktop.org/Tango_Icon_Library
-* Hpricot: http://hpricot.com
If you manage to install Noosfero successfully on other systems than Debian,
please feel free to contact the Noosfero development mailing with the
=====================================
app/helpers/application_helper.rb
=====================================
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1394,16 +1394,16 @@ module ApplicationHelper
end
def convert_macro(html, source)
- doc = Hpricot(html)
+ doc = Nokogiri::HTML.fragment html
#TODO This way is more efficient but do not support macro inside of
# macro. You must parse them from the inside-out in order to enable
# that.
- doc.search('.macro').each do |macro|
+ doc.css('.macro').each do |macro|
macro_name = macro['data-macro']
result = @plugins.parse_macro(macro_name, macro, source)
macro.inner_html = result.kind_of?(Proc) ? self.instance_exec(&result) : result
end
- doc.html
+ doc.to_html
end
def default_folder_for_image_upload(profile)
=====================================
app/models/article.rb
=====================================
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -1,4 +1,3 @@
-require 'hpricot'
class Article < ActiveRecord::Base
@@ -707,7 +706,7 @@ class Article < ActiveRecord::Base
end
def first_paragraph
- paragraphs = Hpricot(to_html).search('p')
+ paragraphs = Nokogiri::HTML.fragment(to_html).css('p')
paragraphs.empty? ? '' : paragraphs.first.to_html
end
@@ -729,8 +728,8 @@ class Article < ActiveRecord::Base
def body_images_paths
require 'uri'
- Hpricot(self.body.to_s).search('img[@src]').collect do |i|
- (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, URI.escape(i.attributes['src'])).to_s : i.attributes['src']
+ Nokogiri::HTML.fragment(self.body.to_s).css('img[src]').collect do |i|
+ (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, URI.escape(i['src'])).to_s : i['src']
end
end
@@ -767,8 +766,8 @@ class Article < ActiveRecord::Base
end
def first_image
- img = Hpricot(self.lead.to_s).search('img[@src]').first || Hpricot(self.body.to_s).search('img').first
- img.nil? ? '' : img.attributes['src']
+ img = Nokogiri::HTML.fragment(self.lead.to_s).css('img[src]').first || Nokogiri::HTML.fragment(self.body.to_s).search('img').first
+ img.nil? ? '' : img['src']
end
delegate :lat, :lng, :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true
=====================================
app/models/external_feed.rb
=====================================
--- a/app/models/external_feed.rb
+++ b/app/models/external_feed.rb
@@ -14,9 +14,9 @@ class ExternalFeed < ActiveRecord::Base
def add_item(title, link, date, content)
return if content.blank?
- doc = Hpricot(content)
- doc.search('*').each do |p|
- if p.instance_of? Hpricot::Elem
+ doc = Nokogiri::HTML.fragment content
+ doc.css('*').each do |p|
+ if p.instance_of? Nokogiri::XML::Element
p.remove_attribute 'style'
p.remove_attribute 'class'
end
@@ -26,10 +26,10 @@ class ExternalFeed < ActiveRecord::Base
article = TinyMceArticle.new
article.name = title
article.profile = blog.profile
- article.body = content
- article.published_at = date
- article.source = link
- article.profile = blog.profile
+ article.body = content
+ article.published_at = date
+ article.source = link
+ article.profile = blog.profile
article.parent = blog
article.author_name = self.feed_title
unless blog.children.exists?(:slug => article.slug)
=====================================
app/models/forum.rb
=====================================
--- a/app/models/forum.rb
+++ b/app/models/forum.rb
@@ -54,7 +54,7 @@ class Forum < Folder
def first_paragraph
return '' if body.blank?
- paragraphs = Hpricot(body).search('p')
+ paragraphs = Nokogiri::HTML.fragment(body).css('p')
paragraphs.empty? ? '' : paragraphs.first.to_html
end
=====================================
app/models/text_article.rb
=====================================
--- a/app/models/text_article.rb
+++ b/app/models/text_article.rb
@@ -1,6 +1,6 @@
require 'noosfero/translatable_content'
-# a base class for all text article types.
+# a base class for all text article types.
class TextArticle < Article
xss_terminate :only => [ :name ], :on => 'validation'
@@ -26,10 +26,10 @@ class TextArticle < Article
before_save :set_relative_path
def set_relative_path
- parsed = Hpricot(self.body.to_s)
- parsed.search('img[@src]').map { |i| change_element_path(i, 'src') }
- parsed.search('a[@href]').map { |i| change_element_path(i, 'href') }
- self.body = parsed.to_s
+ parsed = Nokogiri::HTML.fragment(self.body.to_s)
+ parsed.css('img[src]').each { |i| change_element_path(i, 'src') }
+ parsed.css('a[href]').each { |i| change_element_path(i, 'href') }
+ self.body = parsed.to_html
end
def change_element_path(el, attribute)
=====================================
debian/control
=====================================
--- a/debian/control
+++ b/debian/control
@@ -48,7 +48,6 @@ Depends: adduser,
ruby-feedparser,
ruby-feedparser (>= 0.7-3~),
ruby-gettext,
- ruby-hpricot,
ruby-memcache-client,
ruby-minitest,
ruby-nokogiri,
=====================================
lib/noosfero/plugin/macro.rb
=====================================
--- a/lib/noosfero/plugin/macro.rb
+++ b/lib/noosfero/plugin/macro.rb
@@ -35,7 +35,7 @@ class Noosfero::Plugin::Macro
def attributes(macro)
macro.attributes.to_hash.
select {|key, value| key[0..10] == 'data-macro-'}.
- inject({}){|result, a| result.merge({a[0][11..-1] => a[1]})}.
+ inject({}){|result, a| result.merge({a[0][11..-1] => a[1].to_s})}.
with_indifferent_access
end
=====================================
plugins/comment_group/lib/ext/article.rb
=====================================
--- a/plugins/comment_group/lib/ext/article.rb
+++ b/plugins/comment_group/lib/ext/article.rb
@@ -9,7 +9,7 @@ class Article
def not_empty_group_comments_removed
if body && body_changed?
groups_with_comments = Comment.find(:all, :select => 'distinct group_id', :conditions => {:source_id => self.id}).map(&:group_id).compact
- groups = Hpricot(body.to_s).search('.macro').collect{|element| element['data-macro-group_id'].to_i}
+ groups = Nokogiri::HTML.fragment(body.to_s).css('.macro').collect{|element| element['data-macro-group_id'].to_i}
errors[:base] << (N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty?
end
end
=====================================
plugins/community_track/lib/community_track_plugin/track.rb
=====================================
--- a/plugins/community_track/lib/community_track_plugin/track.rb
+++ b/plugins/community_track/lib/community_track_plugin/track.rb
@@ -59,7 +59,7 @@ class CommunityTrackPlugin::Track < Folder
def first_paragraph
return '' if body.blank?
- paragraphs = Hpricot(body).search('p')
+ paragraphs = Nokogiri::HTML.fragment(body).css('p')
paragraphs.empty? ? '' : paragraphs.first.to_html
end
=====================================
script/install-dependencies/debian-squeeze.sh
=====================================
--- a/script/install-dependencies/debian-squeeze.sh
+++ b/script/install-dependencies/debian-squeeze.sh
@@ -5,7 +5,7 @@ run sudo apt-get -y install $runtime_dependencies
sudo apt-get -y install iceweasel || sudo apt-get -y install firefox
# needed for development
-run sudo apt-get -y install libtidy-ruby libhpricot-ruby libmocha-ruby imagemagick po4a xvfb libxml2-dev libxslt-dev postgresql openjdk-6-jre
+run sudo apt-get -y install libtidy-ruby libmocha-ruby imagemagick po4a xvfb libxml2-dev libxslt-dev postgresql openjdk-6-jre
gem which bundler >/dev/null 2>&1 || gem_install bundler
setup_rubygems_path
run bundle install
=====================================
test/functional/cms_controller_test.rb
=====================================
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -663,8 +663,8 @@ class CmsControllerTest < ActionController::TestCase
should 'be able to add image with alignment' do
post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'image-alignment', :body => "the text of the article with image <img src='#' align='right'/> right align..." }
saved = TinyMceArticle.find_by_name('image-alignment')
- assert_match /<img.*src="#".*\/>/, saved.body
- assert_match /<img.*align="right".*\/>/, saved.body
+ assert_match /<img.*src="#".*>/, saved.body
+ assert_match /<img.*align="right".*>/, saved.body
end
should 'be able to add image with alignment when textile' do
=====================================
test/functional/profile_editor_controller_test.rb
=====================================
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -500,7 +500,7 @@ class ProfileEditorControllerTest < ActionController::TestCase
xhr :get, :update_categories, :profile => profile.identifier, :category_id => top.id
assert_template 'shared/update_categories'
assert_equal top, assigns(:current_category)
- assert_equal [c1, c2], assigns(:categories)
+ assert_equivalent [c1, c2], assigns(:categories)
end
should 'display manage my groups button for person' do
=====================================
test/test_helper.rb
=====================================
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -3,7 +3,6 @@ ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'rails/test_help'
require 'mocha'
-require 'hpricot'
require 'noosfero/test'
require 'authenticated_test_helper'
=====================================
test/unit/application_helper_test.rb
=====================================
--- a/test/unit/application_helper_test.rb
+++ b/test/unit/application_helper_test.rb
@@ -261,7 +261,7 @@ class ApplicationHelperTest < ActionView::TestCase
fast_create(Community, :is_template => true, :environment_id => environment.id)
environment.community_default_template= community
environment.save
-
+
assert_tag_in_string template_options(:communities, 'community'), :tag => 'input',
:attributes => { :name => "community[template_id]", :value => community.id, :checked => true }
end
@@ -273,7 +273,7 @@ class ApplicationHelperTest < ActionView::TestCase
fast_create(Person, :is_template => true, :environment_id => environment.id)
environment.person_default_template= person
environment.save
-
+
assert_tag_in_string template_options(:people, 'profile_data'), :tag => 'input',
:attributes => { :name => "profile_data[template_id]", :value => person.id, :checked => true }
end
@@ -287,7 +287,7 @@ class ApplicationHelperTest < ActionView::TestCase
environment.enterprise_default_template= enterprise
environment.save
environment.reload
-
+
assert_tag_in_string template_options(:enterprises, 'create_enterprise'), :tag => 'input',
:attributes => { :name => "create_enterprise[template_id]", :value => enterprise.id, :checked => true }
end
@@ -734,16 +734,16 @@ class ApplicationHelperTest < ActionView::TestCase
<div class='macro nonEdit' data-macro='unexistent' data-macro-param='987'></div>
"
parsed_html = convert_macro(html, mock())
- parsed_divs = Hpricot(parsed_html).search('div')
- expected_divs = Hpricot("
- <div data-macro='#{macro1_name}' class='parsed-macro #{macro1_name}'>Test1</div>
- <div data-macro='#{macro2_name}' class='parsed-macro #{macro2_name}'>Test2</div>
+ parsed_divs = Nokogiri::HTML.fragment(parsed_html).css('div')
+ expected_divs = Nokogiri::HTML.fragment("
+ <div class='parsed-macro #{macro1_name}' data-macro='#{macro1_name}'>Test1</div>
+ <div class='parsed-macro #{macro2_name}' data-macro='#{macro2_name}'>Test2</div>
<div data-macro='unexistent' class='failed-macro unexistent'>Unsupported macro unexistent!</div>
- ").search('div')
+ ").css('div')
# comparing div attributes between parsed and expected html
parsed_divs.each_with_index do |div, i|
- assert_equal expected_divs[i].attributes.to_hash, div.attributes.to_hash
+ assert_equal expected_divs[i].attributes.to_xml, div.attributes.to_xml
assert_equal expected_divs[i].inner_text, div.inner_text
end
end
=====================================
test/unit/comment_helper_test.rb
=====================================
--- a/test/unit/comment_helper_test.rb
+++ b/test/unit/comment_helper_test.rb
@@ -137,7 +137,7 @@ class CommentHelperTest < ActiveSupport::TestCase
plugin_action = {:link => 'plugin_action', :action_bar => true}
@plugins.stubs(:dispatch).returns([plugin_action])
html = comment_actions(comment)
- assert_match /plugin_action/, Hpricot(html).search('.comments-action-bar').html
+ assert_match /plugin_action/, Nokogiri::HTML.fragment(html).css('.comments-action-bar').to_html
end
def link_to_function(content, url, options = {})
=====================================
test/unit/external_feed_test.rb
=====================================
--- a/test/unit/external_feed_test.rb
+++ b/test/unit/external_feed_test.rb
@@ -166,7 +166,7 @@ class ExternalFeedTest < ActiveSupport::TestCase
next if a.kind_of?(RssFeed)
dd << a.body.to_s.strip.gsub(/\s+/, ' ')
end
- assert_equal '<img src="noosfero.png" /><p>Html content 1.</p><p>Html content 2.</p>', dd.sort.join
+ assert_equal '<img src="noosfero.png"><p>Html content 1.</p><p>Html content 2.</p>', dd.sort.join
end
should 'use feed title as author name' do
=====================================
test/unit/macro_test.rb
=====================================
--- a/test/unit/macro_test.rb
+++ b/test/unit/macro_test.rb
@@ -15,7 +15,7 @@ class MacroTest < ActiveSupport::TestCase
def setup
@macro = Plugin1::Macro.new
- @macro_element = Hpricot(MACRO).search('.macro').first
+ @macro_element = Nokogiri::HTML.fragment(MACRO).css('.macro').first
end
attr_reader :macro, :macro_element
=====================================
test/unit/text_article_test.rb
=====================================
--- a/test/unit/text_article_test.rb
+++ b/test/unit/text_article_test.rb
@@ -1,9 +1,9 @@
require_relative "../test_helper"
class TextArticleTest < ActiveSupport::TestCase
-
+
# mostly dummy test. Can be removed when (if) there are real tests for this
- # this class.
+ # this class.
should 'inherit from Article' do
assert_kind_of Article, TextArticle.new
end
@@ -44,7 +44,7 @@ class TextArticleTest < ActiveSupport::TestCase
env = Environment.default
article.body = "<img src=\"http://#{env.default_hostname}/test.png\" />"
article.save!
- assert_equal "<img src=\"/test.png\" />", article.body
+ assert_equal "<img src=\"/test.png\">", article.body
end
should 'change link to relative path' do
@@ -60,18 +60,18 @@ class TextArticleTest < ActiveSupport::TestCase
person = create_user('testuser').person
article = TextArticle.new(:profile => person, :name => 'test')
env = Environment.default
- article.body = "<img src=\"https://#{env.default_hostname}/test.png\" />"
+ article.body = "<img src=\"https://#{env.default_hostname}/test.png\">"
article.save!
- assert_equal "<img src=\"/test.png\" />", article.body
+ assert_equal "<img src=\"/test.png\">", article.body
end
should 'change image path to relative for domain with port' do
person = create_user('testuser').person
article = TextArticle.new(:profile => person, :name => 'test')
env = Environment.default
- article.body = "<img src=\"http://#{env.default_hostname}:3000/test.png\" />"
+ article.body = "<img src=\"http://#{env.default_hostname}:3000/test.png\">"
article.save!
- assert_equal "<img src=\"/test.png\" />", article.body
+ assert_equal "<img src=\"/test.png\">", article.body
end
should 'change image path to relative for domain with www' do
@@ -80,16 +80,16 @@ class TextArticleTest < ActiveSupport::TestCase
env = Environment.default
env.force_www = true
env.save!
- article.body = "<img src=\"http://#{env.default_hostname}:3000/test.png\" />"
+ article.body = "<img src=\"http://#{env.default_hostname}:3000/test.png\">"
article.save!
- assert_equal "<img src=\"/test.png\" />", article.body
+ assert_equal "<img src=\"/test.png\">", article.body
end
should 'not be translatable if there is no language available on environment' do
environment = fast_create(Environment)
environment.languages = nil
profile = fast_create(Person, :environment_id => environment.id)
-
+
text = TextArticle.new(:profile => profile)
assert !text.translatable?
@@ -102,11 +102,10 @@ class TextArticleTest < ActiveSupport::TestCase
text = fast_create(TextArticle, :profile_id => profile.id)
assert !text.translatable?
-
environment.languages = ['en','pt','fr']
environment.save
- text.reload
+ text.reload
assert text.translatable?
end
=====================================
test/unit/tiny_mce_article_test.rb
=====================================
--- a/test/unit/tiny_mce_article_test.rb
+++ b/test/unit/tiny_mce_article_test.rb
@@ -9,7 +9,7 @@ class TinyMceArticleTest < ActiveSupport::TestCase
end
attr_reader :profile
- # this test can be removed when we get real tests for TinyMceArticle
+ # this test can be removed when we get real tests for TinyMceArticle
should 'be an article' do
assert_subclass TextArticle, TinyMceArticle
end
@@ -44,11 +44,6 @@ class TinyMceArticleTest < ActiveSupport::TestCase
assert(article.body.is_utf8?, "%s expected to be valid UTF-8 content" % article.body.inspect)
end
- should 'fix tinymce mess with itheora comments for IE from tiny mce article body' do
- article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "the <!--–-[if IE]--> just for ie... <!--[endif]-->")
- assert_equal "the <!–-[if IE]> just for ie... <![endif]-–>", article.body.html_safe
- end
-
should 'remove iframe if it is not from a trusted site' do
article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "<iframe src='http://anything/videos.ogg'></iframe>")
assert_equal "", article.body
@@ -94,12 +89,6 @@ class TinyMceArticleTest < ActiveSupport::TestCase
assert_equal '', article.body
end
- #TinymMCE convert config={"key":(.*)} in config={"key":(.*)}
- should 'not replace " with " when adding an Archive.org video' do
- article = create(TinyMceArticle, :profile => profile, :name => 'article', :abstract => 'abstract', :body => "<embed flashvars='config={"key":"\#$b6eb72a0f2f1e29f3d4"}'> </embed>")
- assert_equal "<embed flashvars=\"config={"key":"\#$b6eb72a0f2f1e29f3d4"}\"> </embed>", article.body
- end
-
should 'not sanitize html comments' do
article = TinyMceArticle.new
article.body = '<p><!-- <asdf> << aasdfa >>> --> <h1> Wellformed html code </h1>'
=====================================
vendor/cardmagic-contacts-f66219e6589ccaf3ab9e3574fdd41225d0dd5073/lib/contacts/aol.rb
=====================================
--- a/vendor/cardmagic-contacts-f66219e6589ccaf3ab9e3574fdd41225d0dd5073/lib/contacts/aol.rb
+++ b/vendor/cardmagic-contacts-f66219e6589ccaf3ab9e3574fdd41225d0dd5073/lib/contacts/aol.rb
@@ -8,20 +8,19 @@ class Hash
end
class Contacts
- require 'hpricot'
class Aol < Base
URL = "http://www.aol.com/"
LOGIN_URL = "https://my.screenname.aol.com/_cqr/login/login.psp"
LOGIN_REFERER_URL = "http://webmail.aol.com/"
LOGIN_REFERER_PATH = "sitedomain=sns.webmail.aol.com&lang=en&locale=us&authLev=0&uitype=mini&loginId=&redirType=js&xchk=false"
AOL_NUM = "29970-343" # this seems to change each time they change the protocol
-
+
CONTACT_LIST_URL = "http://webmail.aol.com/#{AOL_NUM}/aim-2/en-us/Lite/ContactList.aspx?folder=Inbox&showUserFolders=False"
CONTACT_LIST_CSV_URL = "http://webmail.aol.com/#{AOL_NUM}/aim-2/en-us/Lite/ABExport.aspx?command=all"
PROTOCOL_ERROR = "AOL has changed its protocols, please upgrade this library first. If that does not work, dive into the code and submit a patch at http://github.com/cardmagic/contacts"
-
+
def real_connect
-
+
postdata = {
"loginId" => login,
"password" => password,
@@ -62,15 +61,15 @@ class Contacts
until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end
-
+
data, resp, cookies, forward, old_url = get("#{LOGIN_URL}?#{LOGIN_REFERER_PATH}", cookies) + [LOGIN_REFERER_URL]
until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end
- doc = Hpricot(data)
- (doc/:input).each do |input|
- postdata["usrd"] = input.attributes["value"] if input.attributes["name"] == "usrd"
+ doc = Nokogiri::HTML.fragment data
+ doc.css('input').each do |input|
+ postdata["usrd"] = input["value"] if input["name"] == "usrd"
end
# parse data for <input name="usrd" value="2726212" type="hidden"> and add it to the postdata
@@ -78,13 +77,13 @@ class Contacts
postdata["SNS_LDC"] = cookie_hash_from_string(cookies)["SNS_LDC"]
postdata["LTState"] = cookie_hash_from_string(cookies)["LTState"]
# raise data.inspect
-
+
data, resp, cookies, forward, old_url = post(LOGIN_URL, postdata.to_query_string, cookies, LOGIN_REFERER_URL) + [LOGIN_REFERER_URL]
-
+
until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end
-
+
if data.index("Invalid Screen Name or Password.")
raise AuthenticationError, "Username and password do not match"
elsif data.index("Required field must not be blank")
@@ -113,19 +112,19 @@ class Contacts
until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end
-
+
if resp.code_type != Net::HTTPOK
raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
end
# parse data and grab <input name="user" value="8QzMPIAKs2" type="hidden">
- doc = Hpricot(data)
- (doc/:input).each do |input|
- postdata["user"] = input.attributes["value"] if input.attributes["name"] == "user"
+ doc = Nokogiri::HTML.fragment data
+ doc.css('input').each do |input|
+ postdata["user"] = input["value"] if input["name"] == "user"
end
-
+
data, resp, cookies, forward, old_url = get(CONTACT_LIST_CSV_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL]
-
+
if forward.nil?
parse data
else
@@ -134,15 +133,15 @@ class Contacts
end
end
private
-
+
def parse(data, options={})
data = CSV.parse(data)
col_names = data.shift
@contacts = data.map do |person|
["#{person[0]} #{person[1]}", person[4]] unless person[4].empty?
end.compact
- end
+ end
end
TYPES[:aol] = Aol
-end
\ No newline at end of file
+end
=====================================
vendor/plugins/ruby_bosh/Rakefile
=====================================
--- a/vendor/plugins/ruby_bosh/Rakefile
+++ b/vendor/plugins/ruby_bosh/Rakefile
@@ -12,7 +12,7 @@ begin
s.add_dependency("builder")
s.add_dependency("rest-client")
- s.add_dependency("hpricot")
+ s.add_dependency("nokogiri")
s.add_dependency("SystemTimer")
end
rescue LoadError
=====================================
vendor/plugins/ruby_bosh/lib/ruby_bosh.rb
=====================================
--- a/vendor/plugins/ruby_bosh/lib/ruby_bosh.rb
+++ b/vendor/plugins/ruby_bosh/lib/ruby_bosh.rb
@@ -2,10 +2,10 @@ require 'rest_client'
require 'builder'
require 'rexml/document'
require 'base64'
-require 'hpricot'
+require 'nokogiri'
require 'timeout'
-class RubyBOSH
+class RubyBOSH
BOSH_XMLNS = 'http://jabber.org/protocol/httpbind'
TLS_XMLNS = 'urn:ietf:params:xml:ns:xmpp-tls'
SASL_XMLNS = 'urn:ietf:params:xml:ns:xmpp-sasl'
@@ -24,12 +24,12 @@ class RubyBOSH
end
attr_accessor :jid, :rid, :sid, :success
- def initialize(jid, pw, service_url, opts={})
+ def initialize(jid, pw, service_url, opts={})
@service_url = service_url
@jid, @pw = jid, pw
@host = jid.split("@").last
@success = false
- @timeout = opts[:timeout] || 3 #seconds
+ @timeout = opts[:timeout] || 3 #seconds
@headers = {"Content-Type" => "text/xml; charset=utf-8",
"Accept" => "text/xml"}
@wait = opts[:wait] || 5
@@ -47,7 +47,7 @@ class RubyBOSH
def connect
initialize_bosh_session
- if send_auth_request
+ if send_auth_request
send_restart_request
request_resource_binding
@success = send_session_request
@@ -55,12 +55,12 @@ class RubyBOSH
raise RubyBOSH::AuthFailed, "could not authenticate #{@jid}" unless success?
@rid += 1 #updates the rid for the next call from the browser
-
+
[@jid, @sid, @rid]
end
private
- def initialize_bosh_session
+ def initialize_bosh_session
response = deliver(construct_body(:wait => @wait, :to => @host,
:hold => @hold, :window => @window,
"xmpp:version" => '1.0'))
@@ -72,7 +72,7 @@ class RubyBOSH
builder = Builder::XmlMarkup.new
parameters = {:rid => @rid, :xmlns => BOSH_XMLNS,
- "xmpp:version" => "1.0",
+ "xmpp:version" => "1.0",
"xmlns:xmpp" => "urn:xmpp:xbosh"}.merge(params)
if block_given?
@@ -82,10 +82,10 @@ class RubyBOSH
end
end
- def send_auth_request
+ def send_auth_request
request = construct_body(:sid => @sid) do |body|
- auth_string = "#{@jid}\x00#{@jid.split("@").first.strip}\x00#{@pw}"
- body.auth(Base64.encode64(auth_string).gsub(/\s/,''),
+ auth_string = "#{@jid}\x00#{@jid.split("@").first.strip}\x00#{@pw}"
+ body.auth(Base64.encode64(auth_string).gsub(/\s/,''),
:xmlns => SASL_XMLNS, :mechanism => 'PLAIN')
end
@@ -100,16 +100,16 @@ class RubyBOSH
def request_resource_binding
request = construct_body(:sid => @sid) do |body|
- body.iq(:id => "bind_#{rand(100000)}", :type => "set",
+ body.iq(:id => "bind_#{rand(100000)}", :type => "set",
:xmlns => "jabber:client") do |iq|
iq.bind(:xmlns => BIND_XMLNS) do |bind|
bind.resource("bosh_#{rand(10000)}")
end
end
end
-
+
response = deliver(request)
- response.include?("<jid>")
+ response.include?("<jid>")
end
def send_session_request
@@ -117,16 +117,16 @@ class RubyBOSH
body.iq(:xmlns => CLIENT_XMLNS, :type => "set",
:id => "sess_#{rand(100000)}") do |iq|
iq.session(:xmlns => SESSION_XMLNS)
- end
+ end
end
response = deliver(request)
- response.include?("body")
+ response.include?("body")
end
def parse(_response)
- doc = Hpricot(_response.to_s)
- doc.search("//body").each do |body|
+ doc = Nokogiri::HTML.fragment(_response.to_s)
+ doc.search("body").each do |body|
@sid = body.attributes["sid"].to_s
end
_response
@@ -156,6 +156,6 @@ end
if __FILE__ == $0
- p RubyBOSH.initialize_session(ARGV[0], ARGV[1],
+ p RubyBOSH.initialize_session(ARGV[0], ARGV[1],
"http://localhost:5280/http-bind")
end
=====================================
vendor/plugins/ruby_bosh/ruby_bosh.gemspec
=====================================
--- a/vendor/plugins/ruby_bosh/ruby_bosh.gemspec
+++ b/vendor/plugins/ruby_bosh/ruby_bosh.gemspec
@@ -24,18 +24,15 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<builder>, [">= 0"])
s.add_runtime_dependency(%q<adamwiggins-rest-client>, [">= 0"])
- s.add_runtime_dependency(%q<hpricot>, [">= 0"])
s.add_runtime_dependency(%q<SystemTimer>, [">= 0"])
else
s.add_dependency(%q<builder>, [">= 0"])
s.add_dependency(%q<adamwiggins-rest-client>, [">= 0"])
- s.add_dependency(%q<hpricot>, [">= 0"])
s.add_dependency(%q<SystemTimer>, [">= 0"])
end
else
s.add_dependency(%q<builder>, [">= 0"])
s.add_dependency(%q<adamwiggins-rest-client>, [">= 0"])
- s.add_dependency(%q<hpricot>, [">= 0"])
s.add_dependency(%q<SystemTimer>, [">= 0"])
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150224/72ef63e6/attachment-0001.html>
More information about the Noosfero-dev
mailing list