Skip to content

Commit

Permalink
Treat punctuation as hashtag delimiters
Browse files Browse the repository at this point in the history
Unicode ranges for punctuation are simpler than creating a Unicode-aware
word class, so delimit on non-words.

Fixes openstreetmap#4398
  • Loading branch information
mojodna committed Oct 9, 2017
1 parent d1f0cb2 commit 37cf22e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/ui/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ var readOnlyTags = [
/^locale$/
];

// treat all punctuation as hashtag delimiters
// from https://stackoverflow.com/a/25575009
var hashtagRegex = /(#[^\u2000-\u206F\u2E00-\u2E7F\s\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]*)/g;


export function uiCommit(context) {
var dispatch = d3_dispatch('cancel', 'save'),
Expand Down Expand Up @@ -309,7 +313,7 @@ export function uiCommit(context) {
function commentTags() {
return tags.comment
.replace(/http\S*/g, '') // drop anything that looks like a URL - #4289
.match(/#[\w-]+/g);
.match(hashtagRegex);
}

// Extract and clean hashtags from `hashtags`
Expand All @@ -319,7 +323,7 @@ export function uiCommit(context) {
.split(/[,;\s]+/)
.map(function (s) {
if (s[0] !== '#') { s = '#' + s; } // prepend '#'
var matched = s.match(/#[\w-]+/g); // match valid hashtags
var matched = s.match(hashtagRegex);
return matched && matched[0];
}).filter(Boolean); // exclude falsey
}
Expand Down

0 comments on commit 37cf22e

Please sign in to comment.