Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider 211e5cd1 rédigé par HankG's avatar HankG Validation de Dennis Schubert
Parcourir les fichiers

Bugfix 7714 twitter char overflow

closes #7791
parent 6918dbc7
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -11,6 +11,7 @@
* Show error message when creating posts with invalid aspects [#7742](https://github.com/diaspora/diaspora/pull/7742)
* Fix mention syntax backport for two immediately consecutive mentions [#7777](https://github.com/diaspora/diaspora/pull/7777)
* Fix link to 'make yourself an admin' [#7783](https://github.com/diaspora/diaspora/pull/7783)
* Fix calculation of content lengths when cross-posting to twitter [#7791](https://github.com/diaspora/diaspora/pull/7791)
## Features
* Make public stream accessible for logged out users [#7775](https://github.com/diaspora/diaspora/pull/7775)
......
......@@ -4,7 +4,7 @@ class Services::Twitter < Service
include Rails.application.routes.url_helpers
MAX_CHARACTERS = 280
SHORTENED_URL_LENGTH = 21
SHORTENED_URL_LENGTH = 23
LINK_PATTERN = %r{https?://\S+}
def provider
......@@ -69,7 +69,7 @@ class Services::Twitter < Service
host: AppConfig.pod_uri.authority
)
truncated_text = post_text.truncate max_characters - SHORTENED_URL_LENGTH + 1
truncated_text = post_text.truncate max_characters - SHORTENED_URL_LENGTH - 1
truncated_text = restore_truncated_url truncated_text, post_text, max_characters
"#{truncated_text} #{post_url}"
......
......@@ -54,7 +54,9 @@ describe Services::Twitter, :type => :model do
it "should truncate a long message" do
long_message = SecureRandom.hex(360)
long_post = double(message: double(plain_text_without_markdown: long_message), id: 1, photos: [])
expect(@service.send(:build_twitter_post, long_post).length).to be < long_message.length
answer = @service.send(:build_twitter_post, long_post)
expect(answer.length).to be < long_message.length
expect(answer).to include "http:"
end
it "should not truncate a long message with an http url" do
......@@ -104,11 +106,11 @@ describe Services::Twitter, :type => :model do
end
it "should not truncate a message of maximum length" do
exact_size_message = SecureRandom.hex(70)
exact_size_post = double(message: double(plain_text_without_markdown: exact_size_message), id: 1, photos: [])
answer = @service.send(:build_twitter_post, exact_size_post)
exact_size_message = SecureRandom.hex(140)
exact_size_post = double(message: double(plain_text_without_markdown: exact_size_message), id: 1, photos: [])
answer = @service.send(:build_twitter_post, exact_size_post)
expect(answer).to match exact_size_message
expect(answer).to match exact_size_message
end
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter