Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

Conversation

@parshap
Copy link
Contributor

@parshap parshap commented Aug 18, 2015

When tweeting commit messages, preserve the original commit message whitespace and tweet it as-is.

Previously, String#split(" ") was used to process words, which splits on any whitespace and with runs of contiguous whitespace characters ignored. When the split array was turned back into a string with Array#join(" "), original whitespace characters were lost and replaced by a single space character.

Now, String#gsub and a regular expression is used to process words, which will preserve the original whitespace.

Fixes #959.

/cc @domenic @kdaigle

When tweeting commit messages, preserve the original commit message
whitespace and tweet it as-is.

Previously, String#split(" ") was used to process words, which splits on
*any* whitespace and with runs of contiguous whitespace characters
ignored [1]. When the split array was turned back into a string with
Array#join(" "), original whitespace characters were lost and replaced
by a single space character.

Now, String#gsub and a regular expression is used to process words,
which will preserve original whitespace.

Fixes #959.

[1] http://ruby-doc.org/core-2.2.0/String.html#method-i-split
@kdaigle
Copy link
Member

kdaigle commented Aug 18, 2015

This looks reasonable to me!

@ptoomey3 can you take a look at this for a 👍? A regex changed but I'm pretty confident, since it is only changing how we escape at-mentions, that it is good to go.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total nit, but would [[:graph:]] be more accurate here? For example:

"foob @\tbar".gsub(/\B@[^ ]+/) { |word| puts word; "@X#{word[1..word.length]}" }
@   bar
=> "foob @X\tbar"

vs

"foob @\tbar".gsub(/\B@[[:graph:]]+/) { |word| puts word; "@X#{word[1..word.length]}" }
=> "foob @\tbar"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, [^ ] is definitely too specific. I looked at what Twitter themselves look for when matching mentions, and it looks like the @ must be followed by [a-zA-Z0-9_]{1,20}.

I changed the regex to use [^[:word:]] and added tests for this behavior.

Change regex to be more specific and look for the "@" symbol followed by
a word character instead of any non-space character.

Add tests for this behavior.

See https://github.com/github/github-services/pull/1075/files#r37456732
@parshap
Copy link
Contributor Author

parshap commented Aug 19, 2015

I added a commit to address @ptoomey3's comment.

I also discovered that Twitter matches (0xff20 FULLWIDTH COMMERCIAL AT) in addition to the normal @ (0x40 COMMERCIAL AT), so I added that too.

Edit: Let me know if you want me to squash these commits.

Don't need to match the entire word, just the first word character after
the `@`.
kdaigle added a commit that referenced this pull request Aug 19, 2015
Twitter: Preserve commit message whitespace
@kdaigle kdaigle merged commit d54e099 into github:master Aug 19, 2015
@kdaigle
Copy link
Member

kdaigle commented Aug 19, 2015

Thanks @parshap for getting this fixed up! I'll get this deployed in the next day or two. 🍰

@domenic
Copy link

domenic commented Aug 19, 2015

<3 <3 <3 @parshap

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants