Git Product home page Git Product logo

twitter-text-rb's Introduction

Deprecation Notice!

This repository has been merged into the twitter-text mono-repo to simplify development, testing, creating issues, and pull requests. This repo is now inactive; please continue all activity in the mono-repo and move existing issues there.

twitter-text-rb's People

Contributors

amatsuda avatar bcherry avatar caniszczyk avatar couch avatar cwest avatar dadah89 avatar danielgrippi avatar edipofederle avatar eileencodes avatar hoverbird avatar howardr avatar iangreenleaf avatar jakl avatar jmhodges avatar jpbougie avatar jsha avatar kennethkufluk avatar kl-7 avatar kscanne avatar kungfumike avatar mathiasbynens avatar mzsanford avatar niw avatar psychs avatar ryanking avatar seldo avatar sferik avatar tommyh avatar trliner avatar yaauie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitter-text-rb's Issues

twitter-text-1.5.0 permission is 640

twitter-text-1.5.0 is not allowed to read for other owner. it's following situation.

% gem install twitter-text
% gem unpack twitter-text
% cd twitter-text-1.5.0/lib
% ls -l
drwxr-xr-x 10 hsbt wheel 340  1 12 22:01 twitter-text
-rw-r-----  1 hsbt wheel 564  1 12 22:01 twitter-text.rb
% ls -l twitter-text
-rw-r----- 1 hsbt wheel 22215  1 12 22:01 autolink.rb
-rw-r----- 1 hsbt wheel   447  1 12 22:01 deprecation.rb
-rw-r----- 1 hsbt wheel 12488  1 12 22:01 extractor.rb
-rw-r----- 1 hsbt wheel  2784  1 12 22:01 hit_highlighter.rb
-rw-r----- 1 hsbt wheel 17123  1 12 22:01 regex.rb
-rw-r----- 1 hsbt wheel  1941  1 12 22:01 rewriter.rb
-rw-r----- 1 hsbt wheel   916  1 12 22:01 unicode.rb
-rw-r----- 1 hsbt wheel  4614  1 12 22:01 validation.rb

For example, application user installed twitter-text, but apache2 user used twitter-text. it happend LoadError.

Please adding to other users reading permission and bump version 1.5.1.

Thanks.

LoadError when requiring twitter-text as a dependency

The t gem depends on twitter-text to extract mentioned screen names from Tweet text.

Five separate users, all on different operating systems and Ruby versions, reported a LoadError on the line where I require 'twitter-text'.

Originally, I assumed it was an environmental issue, since I was unable to reproduce the problem on my machine, however, when I released a version of the gem (0.9.4), which lazy-loaded twitter-text, users reported the problem had been fixed.

As you can see from this GitHub compare view, the only difference between version 0.9.3, where users were reporting a problem, and 0.9.4, where users reported that it was fixed is the lazy-loading of twitter-text: sferik/t-ruby@v0.9.3...v0.9.4

Again, I am unable to reproduce the error, but I believe that there is a problem with requiring twitter-text as a dependency on some systems, which I thought you'd want to know about.

I am considering reimplementing the extract_mentioned_screen_names functionality that I'm using from twitter-text within the t gem, however I'd prefer to depend on twitter-text than maintain that code myself.

Escaping HTML

When using <%= auto_link("link @user, please #request") %>

It returns escaped html in the view, I cant find a way to get usable HTML

HTML attrs for specific entity types

I am finding it difficult to use different html attributes for different entity types (i.e. url, screen name, entity, cashtag). I have ended up recreating the code here...

https://github.com/twitter/twitter-text-rb/blob/v1.6.1/lib/twitter-text/autolink.rb#L67

...to add type specific attrs. In my specific case, I could work around this by using class names, but was curious if you would accept a patch for type specific attributes? Another solution I was thinking would be passing in a block that gets called in #auto_link_entities to allow for specific attributes to be changed (very basic example below)

  Twitter::Rewriter.rewrite_entities(text, entities) do |entity, chars|
    if entity[:url]
      options = options.merge(block.call(:url) || {})
      link_to_url(entity, chars, options, &block)
    elsif entity[:hashtag]
      options = options.merge(block.call(:hashtag) || {})
      link_to_hashtag(entity, chars, options, &block)
    elsif entity[:screen_name]
      options = options.merge(block.call(:screen_name) || {})
      link_to_screen_name(entity, chars, options, &block)
    elsif entity[:cashtag]
      options = options.merge(block.call(:cashtag) || {})
      link_to_cashtag(entity, chars, options, &block)
    end
  end

Autolinking a Tweet object from twitter gem v5.2.0 raises an error

The auto_link method raises a RuntimeError when passed the text of a Twitter::Tweet object from the latest version (5.2.0) of the twitter gem.

Here's an example:

require 'twitter' # 5.2.0
require 'twitter-text' # 1.7.0

client = Twitter::REST::Client.new do |config|
  config.consumer_key        = "YOUR_CONSUMER_KEY"
  config.consumer_secret     = "YOUR_CONSUMER_SECRET"
  config.access_token        = "YOUR_ACCESS_TOKEN"
  config.access_token_secret = "YOUR_ACCESS_SECRET"
end

tweet = client.user_timeline('gem').first

Twitter::Autolink.auto_link(tweet.text)
# => RuntimeError: can't modify frozen String

This was working as expected in version 4.8.1, but I haven't tested any of the versions in between.

Errant documentation in README

lib/autolink.rb includes a custom version of link_to. This clobbers Rails' link_to definition and fails on link_to calls that utilize a block. link_to should be enhanced, renamed, or the following should be removed from the documentation:

# For Ruby on Rails you want to add this to app/helpers/application_helper.rb
module ApplicationHelper
  include Twitter::Autolink
end

Would a patch for any of these solutions be accepted?

Broken Conformance: URLs with unicode chars in them

A conformance spec is currently broken on master.

  1) Failure:
test_urls Autolink URLs with unicode chars in them(ConformanceTest) [test/conformance_test.rb:126]:
<"See: <a href=\"http://example.com/tsa-pre✓™\">http://example.com/tsa-pre✓™</a> is a link"> expected but was
<"See: <a href=\"http://example.com/tsa-pre\">http://example.com/tsa-pre</a>✓™ is a link">

In this case, the unicode characters are not being included in the matched URL when we expect them to be.

I believe @psychs addressed the rationale behind what should and shouldn't match in #91, but I don't believe the spec is clear enough which unicode codepoint ranges should be considered part of the URL, and which shouldn't.

A solution to this issue would be to fix the spec; alternatively, I can take on the task of fixing it given documentation on what codepoint ranges should be considered part of the URL.

Link break for mention string having '-' character

My mention string has hyphen in between when I am trying to create link it break because of '-'.

mention_str = "sunny-b"
puts Twitter::Autolink.auto_link(mention_str, :username_include_symbol => true)

O/P - sunny-b with invalid URL

Newlines break hashtag extraction

I'm trying to extract the hashtags from the text of this Tweet using the Twitter::Extractor.extract_hashtags method.

It's hard to see on the Twitter website, but the text string contains various newline characters:

"#bieber\n#justinbieber \n#bangersgarlingistrending \nRT if you are mega excited about biebs' 'secret' show coming in January to The Metro"

I expect the result to be:

["bieber", "justinbieber", "bangersgarlingistrending"]

instead of just:

["bangersgarlingistrending"]

Open url in a seperate window

I am not sure if this can be done now but I would like to open up the url's in a seperate browser window. Is this possible or does this functionality need to be added?

Cannot extract international text with correct indice in a rails project

I was playing with it in my rails console (jruby-1.6.7, rails 3.2) and found things were not quite correct if I extract mentions/hashtags with japanese or chinese text with indices, the screen name was correctly returned, but the indices is not correct.

Then I created a spec in my rails project and copied from twitter-text-rb/spec/extrator_spec into it, and I got failed tests if I run it in my rails project. I created a gist for the results. https://gist.github.com/2204246

Is there any settings to be done for it could be used in a rails project?

I have the Encoding.default_external and Encoding.default_internal already set to Encoding::UTF_8

including Twitter::Autolink breaks Rails' auto_link for emails

are you generally supporting Rails' auto_link or is twitter_text's autolink to be used only for Tweets? the impression i got from the twitter-text docu was that part of the gem's functionality is to extend the default auto_link's capabilities to link to tweet authors etc.

when i include Twitter::Autolink in my application helper emails are no longer auto_linked in my views. when i remove the include they work again. in the views i have a normal call like:
= auto_link @text

i'm using:

  • the latest twitter/twitter-text-rb (github path in gemfile, pulled just now)
  • ruby-1.9.3-p0
  • Rails 3.1.1
  • rails_autolink (1.0.4) (via Rubygems)

simple demo in my rails console (as far as i understand it helper.auto_link uses 'pure' default auto_link while plain auto_link, after the Twitter::Autolink include, uses a method extende by twitter-text):

ruby-1.9.3-p0 :002 > helper.auto_link '[email protected] hahaha'
=> "<a href="mailto:[email protected]">[email protected] hahaha"

ruby-1.9.3-p0 :003 > include Twitter::Autolink
=> Object
ruby-1.9.3-p0 :004 > helper.auto_link '[email protected] hahaha'
=> "<a href="mailto:[email protected]">[email protected] hahaha"

ruby-1.9.3-p0 :006 > auto_link '[email protected] hahaha'
=> "[email protected] hahaha"
uby-1.9.3-p0 :007 > auto_link "This is a #tweet with a @username"
=> "This is a <a href="http://twitter.com/search?q=%23tweet\" title="#tweet" class="tweet-url hashtag" rel="nofollow">#tweet with a @<a class="tweet-url username" href="http://twitter.com/username\" rel="nofollow">username"

ruby-1.9.3-p0 :008 > helper.auto_link "This is a #tweet with a @username"
=> "This is a #tweet with a @username"

No read access to gem installing via sudo

Installing this gem via sudo give root user read access to the files.

Install gem:

sudo gem install 'twitter-text' --version 1.4.13

Start irb

require 'rubygems'
require 'twitter-text'
=> LoadError: no such file to load -- twitter-text

All files in /usr/lib/ruby/gems/1.8/gems/twitter-text-1.4.13/lib permissions of 660 (rw-rw----). I needed to manually add read permissions for non-root users to all files in the lib directory.

Twitter::Autolink breaks in jruby when text contains Chinese or Japanese

I just has this test:

with jruby-1.6.7.2 1.9 mode:

$ jruby -S test.rb
=== original ===
@baozi hi you are a dog #dog
@baozi 嗨你是一条狗诶 #狗狗
@baozi ねえ、あなたは犬だ #犬
=== autolinked ===
<a class="tweet-url username" href="https://twitter.com/baozi" rel="nofollow">@baozi</a> hi you are a dog <a class="tweet-url hashtag" href="https://twitter.com/#!/search?q=%23dog" rel="nofollow" title="#dog">#dog</a>
@baozi 嗨你是一条狗诶 #狗<a class="tweet-url username" href="https://twitter.com/baozi" rel="nofollow">狗baozi</a><a class="tweet-url hashtag" href="https://twitter.com/#!/search?q=%23狗狗" rel="nofollow" title="#狗狗">@狗狗</a>@baozi 嗨你是一条狗诶 #狗狗
@baozi ねえ、あなたは犬だ #<a class="tweet-url username" href="https://twitter.com/baozi" rel="nofollow">犬baozi</a><a class="tweet-url hashtag" href="https://twitter.com/#!/search?q=%23犬" rel="nofollow" title="#犬">@犬</a>@baozi ねえ、あなたは犬だ #犬

The autolink breaks when test contains Chinese/Japanese. But this only happens with jruby, if I use MRI ruby, everything is fine.

The code I use to test is here: https://gist.github.com/3045668

Autolink drops capitalization

Using 1.6.1:

>  Twitter::Autolink.auto_link("@Bob hello")
=> "@<a class=\"tweet-url username\" href=\"https://twitter.com/bob\" rel=\"nofollow\">bob</a> hello"

Is there a reason why Autolink would drop capitalization?

Wrongly auto-linking email addresses as mentions.

It seems that the auto_link method is wrongly detecting email addresses as mentions and linking them.

Twitter::Autolink.auto_link_usernames_or_lists 'My email is [email protected]'
 => "My email is robert@<a class=\"tweet-url username\" href=\"https://twitter.com/weboffins\" rel=\"nofollow\">weboffins</a>.com" 

This feels counter intuitive to me as it creates invalid links, and also present conflicts when used with the rinku gem for linking emails with mailto://

URLs are being mangled

Hi,

I've just started using this gem, and am encountering a problem when auto_linking URLs. I've added 'include Twitter::AutoLink' into my ApplicationHelper, however when I do the following, I'm getting unexpected results:

text = "@gavinlaking"
"@gavinlaking"

auto_link(text)
"@<a class=\"tweet-url username\" href=\"http://twitter.com/gavinlaking\" rel=\"nofollow\">gavinlaking</a>"

Okay so far... so let's try a URL:

text = "http://www.example.com"
"http://www.example.com"

auto_link(text)
"<a href=\"http://www.example.com\"{:xmlns=>\"http://www.w3.org/1999/xhtml\", \"xml:lang\"=<{:rel=>\"nofollow\", :class=<nil}, :lang=>{:rel=<\"nofollow\", :class=>nil}}<http://www.example.com>/a<"

It looks like the brackets are the wrong way around, and also we have a hash in the middle of our HTML.

Any ideas?

Enabling protocol in autolinked URLs

I'm using the Java library and am wondering how I can make sure the protocol is included the extracted href. Not including the protocol in the link can cause issues when a non https external url is linked to from a site with SSL. Is there a way to ensure the protocol is included instead of producing href="//..?

ruby 1.8.7 KCODE

I just spent ages trying to get this to work on ruby 1.8.7 and rubygems 1.5.3. Now I have it working. At the top of my script I needed to do:

require 'rubygems'
$KCODE='u'
require 'twitter'
require 'twitter-text'
include Twitter::Autolink 

KCODE='u' is a bit of magic I found at the bottom of a discussion on a google cached copy of the old issue tracker here: http://webcache.googleusercontent.com/search?q=cache:iAS36VNIoLYJ:https://github.com/mzsanford/twitter-text-rb/issues/8+twitter-text+requires+the+%24KCODE+variable+be+set+to+%27UTF8%27&cd=5&hl=en&ct=clnk&client=ubuntu

(took me a while to find!) As I say, I got it working, so this is maybe just a comment on the documentation, or not even that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.