Skip to content

Commit

Permalink
Limit hashtags to alphanumeric characters and underscores; remove art…
Browse files Browse the repository at this point in the history
…ifacts

This should help with #3 for now.
  • Loading branch information
theopolisme committed Aug 8, 2014
1 parent 6520595 commit e7d1203
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
titles: name
}, function ( data, next, raw ) {
var xml = data.pages[data.pageids[0]].revisions[0].parsetree;
console.log( xml );
callback && callback( xml );
}, 'POST' );
}
Expand Down Expand Up @@ -67,11 +66,16 @@
return false;
}

return he.decode(
name
.replace( /^wikiproject\s*/i, '' )
.replace( /\s*/g, '' )
);
// Convert html entities to normal characters
name = he.decode( name );

// Remove "WikiProject" from beginning of hashtag
name = name.replace( /^wikiproject/i, '' );

// Hashtags can only contain alphanumeric characters and underscores
name = name.replace( /[^a-z0-9_]/gi, '' );

This comment has been minimized.

Copy link
@phuedx

phuedx Aug 9, 2014

Contributor

If you used /[\p{Alnum}]/gui here, then you'll avoid stripping Unicode alphanumeric characters.

This comment has been minimized.

Copy link
@theopolisme

theopolisme Aug 9, 2014

Author Owner

I didn't think this was supported in JS (at least ES5 – the u modifier is part of ES6)...

This comment has been minimized.

Copy link
@phuedx

phuedx Aug 9, 2014

Contributor

Derp. Wrong language. However, JavaScript definitely supports \W.

This comment has been minimized.

Copy link
@theopolisme

theopolisme Aug 9, 2014

Author Owner

\W doesn't help with Unicode, though... JavaScript's \W & \w only support ASCII characters (in ES5). So yeah, it's functionally the same to the existing regexp although imho not as clear.

/\W/.test( 'é' ) => true

This comment has been minimized.

Copy link
@phuedx

phuedx Aug 10, 2014

Contributor

So yeah, it's functionally the same to the existing regexp although imho not as clear.

We'll have to agree to disagree about that one.


return name;
}

for ( i; i < templateNames.length; i++ ) {
Expand Down Expand Up @@ -145,7 +149,6 @@
}

if ( hashtags.length ) {
// Remove Talk: from url
tweet = makeTweet( articleName, hashtags, articleUrl );
}

Expand Down

0 comments on commit e7d1203

Please sign in to comment.