Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/services/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def receive_push
url = commit['url']
# Strip out leading @s so that github @ mentions don't become twitter @ mentions
# since there's zero reason to believe IDs on one side match IDs on the other
message = commit['message'].split(' ').map do |word|
(word.length > 1 && word[0] == '@') ? "@\u200b#{word[1..word.length]}" : word
end.join(' ')
message = commit['message'].gsub(/\B[@@][[:word:]]/) do |word|
"@\u200b#{word[1..word.length]}"
end
status = if short_format?
"#{url} #{message}"
else
Expand Down
28 changes: 24 additions & 4 deletions test/twitter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,31 @@ def svc.post(status)
end
end

# Make sure that whitespace in the original commit message is preserved
def test_whitespace
p = payload
p['commits'][0]['message']="message \nwith\n\n weird whitespace "
svc = service({'token' => 't', 'secret' => 's'}, p)

def svc.statuses
@statuses ||= []
end

def svc.post(status)
statuses << status
end

svc.receive_push
assert svc.statuses[0].match(p['commits'][0]['message'])
end

# Make sure that GitHub @mentions are injected with a zero-width space
# so that they don't turn into (potentially unmatching) twitter @mentionds
def test_mentions
p = payload
p['commits'][0]['message']="This commit was done by @sgolemon"
p['commits'][1]['message']="@sgolemon committed this"
p['commits'][2]['message']="@sgolemon made a test for @kdaigle"
p['commits'][2]['message']="@sgolemon made a @ @\ttest for @kdaigle"
svc = service({'token' => 't', 'secret' => 's'}, p)

def svc.statuses
Expand All @@ -72,9 +90,11 @@ def svc.post(status)
svc.receive_push
assert_equal 3, svc.statuses.size
svc.statuses.each do |st|
# Any @ which is not followed by U+200B ZERO WIDTH SPACE
# is an error
assert !st.match('@(?!\u200b)')
# Any @ which is followed by a word character is an error
assert !st.match('@(?=[[:word:]])')
# Any @ which is followed by a U+200b ZERO WIDTH SPACE but not a word
# character is an error
assert !st.match('@(?=\u200b[^[:word:]])')
end
end

Expand Down