Skip to content

Commit 5bfed19

Browse files
improve tag handling
1 parent 072840d commit 5bfed19

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/instafeed.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,17 @@
229229
return transformedFiltered;
230230
};
231231

232-
Instafeed.prototype._getTags = function getTags(data) {
233-
// This expression comes from https://github.com/johnlinp/instagram-validator
234-
// A non-official instagram validator
235-
var exp = /^#[^~`!@#$%^&*\(\)\-\+={}\[\]:;"'<>\?,\./|\\\s]+$/gi;
232+
Instafeed.prototype._extractTags = function extractTags(str) {
233+
var exp = /#([^\s]+)/gi;
234+
var badChars = /[~`!@#$%^&*\(\)\-\+={}\[\]:;"'<>\?,\./|\\\s]+/i; // non-allowed characters
236235
var tags = [];
237-
var tagData = data.caption.match(exp) || [];
238236

239-
//Pull the hash character off the front of each tag.
240-
//Can this be done in one hit with the regex?
241-
for (var i = 0; i < tagData.length; i++) {
242-
tags.push(tagData[i].substring(1));
237+
if (typeof str === 'string') {
238+
while ((match = exp.exec(str)) !== null) {
239+
if (badChars.test(match[1]) === false) {
240+
tags.push(match[1]);
241+
}
242+
}
243243
}
244244

245245
return tags;
@@ -266,7 +266,7 @@
266266

267267
return {
268268
caption: data.caption,
269-
tags: this._getTags(data),
269+
tags: this._extractTags(data.caption),
270270
id: data.id,
271271
image: image,
272272
link: data.permalink,

0 commit comments

Comments
 (0)