Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a trailing single curly quote after a $cashtag #179

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions conformance/extract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,10 @@ tests:
text: "#_ #1_2 #122 #〃"
expected: []

- description: "Extract hashtag followed by curly quotes"
text: "#whatshappening’s trending."
expected: [whatshappening]

hashtags_from_astral:
- description: "Extract hashtag with letter from astral plane (U+20021)"
text: "#\U00020021"
Expand Down Expand Up @@ -952,6 +956,10 @@ tests:
text: "$CashtagMustBeLessThanSixCharacter"
expected: []

- description: "Extract cashtag followed by curly quotes"
text: "$Stock’s trending."
expected: [Stock]

cashtags_with_indices:
- description: "Extract cashtags"
text: "Example: $TEST $symbol test"
Expand Down
2 changes: 1 addition & 1 deletion java/src/com/twitter/Regex.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public class Regex {

VALID_URL = Pattern.compile(VALID_URL_PATTERN_STRING, Pattern.CASE_INSENSITIVE);
VALID_TCO_URL = Pattern.compile("^https?:\\/\\/t\\.co\\/[a-z0-9]+", Pattern.CASE_INSENSITIVE);
VALID_CASHTAG = Pattern.compile("(^|" + UNICODE_SPACES + ")(" + DOLLAR_SIGN_CHAR + ")(" + CASHTAG + ")" + "(?=$|\\s|\\p{Punct})", Pattern.CASE_INSENSITIVE);
VALID_CASHTAG = Pattern.compile("(^|" + UNICODE_SPACES + ")(" + DOLLAR_SIGN_CHAR + ")(" + CASHTAG + ")" + "(?=$|\\s|\\p{Punct}|\\u2019)", Pattern.CASE_INSENSITIVE);
Copy link
Contributor

Choose a reason for hiding this comment

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

how about including \u201D, \u275C, \u275E

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a good question. We can evaluate those next.

VALID_DOMAIN = Pattern.compile(URL_VALID_DOMAIN, Pattern.CASE_INSENSITIVE);
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/twitter-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@

// cashtag related regex
twttr.txt.regexen.cashtag = /[a-z]{1,6}(?:[._][a-z]{1,2})?/i;
twttr.txt.regexen.validCashtag = regexSupplant('(^|#{spaces})(\\$)(#{cashtag})(?=$|\\s|[#{punct}])', 'gi');
twttr.txt.regexen.validCashtag = regexSupplant('(^|#{spaces})(\\$)(#{cashtag})(?=$|\\s|[#{punct}]|\\u2019)', 'gi');

// These URL validation pattern strings are based on the ABNF from RFC 3986
twttr.txt.regexen.validateUrlUnreserved = /[a-z\u0400-\u04FF0-9\-._~]/i;
Expand Down
2 changes: 1 addition & 1 deletion objc/lib/TwitterText.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
#define TWUValidSymbol \
@"(?:^|[" TWUUnicodeSpaces @"])" \
@"(\\$" TWUSymbol @")" \
@"(?=$|\\s|[" TWUPunctuationChars @"])"
@"(?=$|\\s|[" TWUPunctuationChars @"]|\\u2019)"

//
// Mention and list name
Expand Down
14 changes: 14 additions & 0 deletions objc/tests/json-conformance/extract.json
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,13 @@
"expected": [

]
},
{
"description": "Extract hashtag followed by curly quotes",
"text": "#whatshappening’s trending.",
"expected": [
"whatshappening"
]
}
],
"hashtags_from_astral": [
Expand Down Expand Up @@ -1901,6 +1908,13 @@
"expected": [

]
},
{
"description": "Extract cashtag followed by curly quotes",
"text": "$Stock’s trending.",
"expected": [
"Stock"
]
}
],
"cashtags_with_indices": [
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/twitter-text/regex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def self.regex_range(from, to = nil) # :nodoc:
}iox

REGEXEN[:cashtag] = /[a-z]{1,6}(?:[._][a-z]{1,2})?/i
REGEXEN[:valid_cashtag] = /(^|#{REGEXEN[:spaces]})(\$)(#{REGEXEN[:cashtag]})(?=$|\s|[#{PUNCTUATION_CHARS}])/i
REGEXEN[:valid_cashtag] = /(^|#{REGEXEN[:spaces]})(\$)(#{REGEXEN[:cashtag]})(?=$|\s|[#{PUNCTUATION_CHARS}]|\u2019)/i

# These URL validation pattern strings are based on the ABNF from RFC 3986
REGEXEN[:validate_url_unreserved] = /[a-z\p{Cyrillic}0-9\-._~]/i
Expand Down