Unverified Commit 211e5cd1 authored by HankG's avatar HankG Committed by Dennis Schubert
Browse files

Bugfix 7714 twitter char overflow

closes #7791
parent 6918dbc7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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)
+2 −2
Original line number Diff line number Diff line
@@ -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}"
+7 −5
Original line number Diff line number Diff line
@@ -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,7 +106,7 @@ 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_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)