# HG changeset patch
# User hamidouk
# Date 1321888816 -3600
# Node ID ed4a459c929038e00fa3fe8bef51a89f28cf63a2
# Parent 10ecc65d945c0e30c89f2cffe109f0b757ecf17c
fixed the formatTweet to create links to urls.
diff -r 10ecc65d945c -r ed4a459c9290 src/js/utils.js
--- a/src/js/utils.js Mon Nov 21 15:45:47 2011 +0100
+++ b/src/js/utils.js Mon Nov 21 16:20:16 2011 +0100
@@ -51,12 +51,15 @@
/* format a tweet - replaces @name by a link to the profile, #hashtag, etc. */
IriSP.formatTweet = function(tweet) {
- var rNickname = /@(\w+)/; // matches a @handle
- var rHashtag = /#(\w+)/; // matches a hashtag
- var i1 = tweet.replace(rNickname, "@$1");
- var i2 = i1.replace(rHashtag, "#$1");
+ var rNickname = /@(\w+)/gi; // matches a @handle
+ var rHashtag = /#(\w+)/gi; // matches a hashtag
+ var rUrl = /((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi; // copied from http://codegolf.stackexchange.com/questions/464/shortest-url-regex-match-in-javascript/480#480
- return i2;
+ var i1 = tweet.replace(rUrl, "$1");
+ var i2 = i1.replace(rNickname, "@$1");
+ var i3 = i2.replace(rHashtag, "#$1");
+
+ return i3;
};
/* for ie compatibility
diff -r 10ecc65d945c -r ed4a459c9290 unittests/tests/utils.js
--- a/unittests/tests/utils.js Mon Nov 21 15:45:47 2011 +0100
+++ b/unittests/tests/utils.js Mon Nov 21 16:20:16 2011 +0100
@@ -39,8 +39,8 @@
});
test("test function to format a tweet", function() {
- var input = "@handle #hashtag ";
- var output = "@handle #hashtag ";
+ var input = "@handle @bundle #hashtag http://t.co/11111";
+ var output = "@handle @bundle #hashtag http://t.co/11111";
equal(IriSP.formatTweet(input), output, "the correct output is given");
});
}
\ No newline at end of file