Ejemplo n.º 1
0
        private void HandleMsg(ChatUser user, string[] parts)
        {
            if (_repository.Users.Count() == 1)
            {
                throw new InvalidOperationException("You're the only person in here...");
            }

            if (parts.Length < 2 || String.IsNullOrWhiteSpace(parts[1]))
            {
                throw new InvalidOperationException("Who are you trying send a private message to?");
            }
            var      toUserName = parts[1];
            ChatUser toUser     = _repository.VerifyUser(toUserName);

            if (toUser == user)
            {
                throw new InvalidOperationException("You can't private message yourself!");
            }

            string messageText = String.Join(" ", parts.Skip(2)).Trim();

            if (String.IsNullOrEmpty(messageText))
            {
                throw new InvalidOperationException(String.Format("What did you want to say to '{0}'.", toUser.Name));
            }

            HashSet <string> urls;
            var transform = new TextTransform(_repository);

            messageText = transform.Parse(messageText);

            messageText = TextTransform.TransformAndExtractUrls(messageText, out urls);

            _notificationService.SendPrivateMessage(user, toUser, messageText);
        }
Ejemplo n.º 2
0
        public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
        {
            if (context.Repository.Users.Count() == 1)
            {
                throw new InvalidOperationException("You're the only person in here...");
            }

            if (args.Length == 0 || String.IsNullOrWhiteSpace(args[0]))
            {
                throw new InvalidOperationException("Who are you trying send a private message to?");
            }
            var      toUserName = HttpUtility.HtmlDecode(args[0]);
            ChatUser toUser     = context.Repository.VerifyUser(toUserName);

            if (toUser == callingUser)
            {
                throw new InvalidOperationException("You can't private message yourself!");
            }

            string messageText = String.Join(" ", args.Skip(1)).Trim();

            if (String.IsNullOrEmpty(messageText))
            {
                throw new InvalidOperationException(String.Format("What did you want to say to '{0}'?", toUser.Name));
            }

            HashSet <string> urls;
            var transform = new TextTransform(context.Repository);

            messageText = transform.Parse(messageText);

            messageText = TextTransform.TransformAndExtractUrls(messageText, out urls);

            context.NotificationService.SendPrivateMessage(callingUser, toUser, messageText);
        }
Ejemplo n.º 3
0
        private string ParseChatMessageText(string content, out HashSet <string> links)
        {
            var    textTransform = new TextTransform(_repository);
            string message       = textTransform.Parse(content);

            return(TextTransform.TransformAndExtractUrls(message, out links));
        }
Ejemplo n.º 4
0
        private string ConvertUrlsAndRoomLinks(string message)
        {
            TextTransform textTransform = new TextTransform(_repository);

            message = textTransform.ConvertHashtagsToRoomLinks(message);
            HashSet <string> urls;

            return(TextTransform.TransformAndExtractUrls(message, out urls));
        }
Ejemplo n.º 5
0
            public void DoNotUnescapeHtmlEntities()
            {
                //arrange
                var message = System.Web.HttpUtility.HtmlEncode("<a href=\"#\" onclick=\"alert('fail')>clickme</a>");
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal(message, result);
            }
Ejemplo n.º 6
0
            public void EncodedUrlWithTrailingQuotationsMatchesUrlButNotTrailingQuotation()
            {
                // Arrange
                var message = "&quot;Visit http://www.jabbr.net/&quot;";
                HashSet <string> extractedUrls;

                // Act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                // Assert
                Assert.Equal("\"Visit <a rel=\"nofollow external\" target=\"_blank\" href=\"http://www.jabbr.net/\" title=\"http://www.jabbr.net/\">http://www.jabbr.net/</a>\"", result);
            }
Ejemplo n.º 7
0
            public void UrlWithHttpsIsTransformed()
            {
                //arrange
                var message = "message https://www.jabbr.net continues on";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("message <a rel=\"nofollow external\" target=\"_blank\" href=\"https://www.jabbr.net\" title=\"https://www.jabbr.net\">https://www.jabbr.net</a> continues on", result);
            }
Ejemplo n.º 8
0
            public void UrlWithAmpersand()
            {
                //arrange
                var message = "message http://google.com/?1&amp;2 continues on";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("message <a rel=\"nofollow external\" target=\"_blank\" href=\"http://google.com/?1&amp;2\" title=\"http://google.com/?1&amp;2\">http://google.com/?1&amp;2</a> continues on", result);
            }
Ejemplo n.º 9
0
            public void UrlWithCallbacks()
            {
                //arrange
                var message = @"http://a.co/a.png#&quot;onerror=&#39;alert(&quot;Eek!&quot;)'";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal(@"http://a.co/a.png#&quot;onerror=&#39;alert(&quot;Eek!&quot;)'", result);
            }
Ejemplo n.º 10
0
            public void UrlWithEllipsisIsTransformed()
            {
                //arrange
                var message = "message https://github.com/NuGet/NuGetGallery/compare/345ea25491...90a05bc3e0 continues on";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("message <a rel=\"nofollow external\" target=\"_blank\" href=\"https://github.com/NuGet/NuGetGallery/compare/345ea25491...90a05bc3e0\" title=\"https://github.com/NuGet/NuGetGallery/compare/345ea25491...90a05bc3e0\">https://github.com/NuGet/NuGetGallery/compare/345ea25491...90a05bc3e0</a> continues on", result);
            }
Ejemplo n.º 11
0
            public void UrlWithUnicodeIsTransformed()
            {
                //arrange
                var message = "message http://➡.ws/䨹 continues on";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("message <a rel=\"nofollow external\" target=\"_blank\" href=\"http://&#10145;.ws/&#19001;\" title=\"http://➡.ws/䨹\">http://➡.ws/䨹</a> continues on", result);
            }
Ejemplo n.º 12
0
            public void UrlWithInvalidButEscapedCharactersMatchesValidUrlSection()
            {
                //arrange
                var message = "message http://google.com/&lt;a&gt; continues on";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("message <a rel=\"nofollow external\" target=\"_blank\" href=\"http://google.com/\" title=\"http://google.com/\">http://google.com/</a><a> continues on", result);
            }
Ejemplo n.º 13
0
            public void BothParenthesis()
            {
                //arrange
                var message = @"(http://foo.com)";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("(<a rel=\"nofollow external\" target=\"_blank\" href=\"http://foo.com\" title=\"http://foo.com\">http://foo.com</a>)", result);
            }
Ejemplo n.º 14
0
            public void UrlWithInvalidButEscapedCharacters()
            {
                //arrange
                var message = "message http://google.com/&lt;a&gt; continues on";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("message http://google.com/&lt;a&gt; continues on", result);
            }
Ejemplo n.º 15
0
            public void UrlInsideAQuotedSentence()
            {
                //arrange
                var message = "This is a sentence with quotes and a url ... see \"http://foo.com\"";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("This is a sentence with quotes and a url ... see \"<a rel=\"nofollow external\" target=\"_blank\" href=\"http://foo.com\" title=\"http://foo.com\">http://foo.com</a>\"", result);
            }
Ejemplo n.º 16
0
            public void UrlEndsWithSlashInsideAQuotedSentence()
            {
                //arrange
                var message = "\"Visit http://www.jabbr.net/\"";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("\"Visit <a rel=\"nofollow external\" target=\"_blank\" href=\"http://www.jabbr.net/\" title=\"http://www.jabbr.net/\">http://www.jabbr.net/</a>\"", result);
            }
Ejemplo n.º 17
0
            public void UnicodeInParens()
            {
                //arrange
                var message = @"http://foo.com/unicode_(✪)_in_parens";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("<a rel=\"nofollow external\" target=\"_blank\" href=\"http://foo.com/unicode_(&#10026;)_in_parens\" title=\"http://foo.com/unicode_(✪)_in_parens\">http://foo.com/unicode_(✪)_in_parens</a>", result);
            }
Ejemplo n.º 18
0
            public void SomethingAfterParens()
            {
                //arrange
                var message = @"http://foo.com/(something)?after=parens";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("<a rel=\"nofollow external\" target=\"_blank\" href=\"http://foo.com/(something)?after=parens\" title=\"http://foo.com/(something)?after=parens\">http://foo.com/(something)?after=parens</a>", result);
            }
Ejemplo n.º 19
0
            public void WikiWithParensAndMoreAndHash()
            {
                //arrange
                var message = @"http://foo.com/blah_(wikipedia)_blah#cite-1";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("<a rel=\"nofollow external\" target=\"_blank\" href=\"http://foo.com/blah_(wikipedia)_blah#cite-1\" title=\"http://foo.com/blah_(wikipedia)_blah#cite-1\">http://foo.com/blah_(wikipedia)_blah#cite-1</a>", result);
            }
Ejemplo n.º 20
0
            public void BitLyWithoutHttp()
            {
                //arrange
                var message = @"bit.ly/foo";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("<a rel=\"nofollow external\" target=\"_blank\" href=\"http://bit.ly/foo\" title=\"bit.ly/foo\">bit.ly/foo</a>", result);
            }
Ejemplo n.º 21
0
            public void MSDN()
            {
                //arrange
                var message = @"http://msdn.microsoft.com/en-us/library/system.linq.enumerable(v=vs.110).aspx";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("<a rel=\"nofollow external\" target=\"_blank\" href=\"http://msdn.microsoft.com/en-us/library/system.linq.enumerable(v=vs.110).aspx\" title=\"http://msdn.microsoft.com/en-us/library/system.linq.enumerable(v=vs.110).aspx\">http://msdn.microsoft.com/en-us/library/system.linq.enumerable(v=vs.110).aspx</a>", result);
            }
Ejemplo n.º 22
0
            public void MoreThanOneSetOfParens()
            {
                //arrange
                var message = @"http://foo.com/more_(than)_one_(parens)";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("<a rel=\"nofollow external\" target=\"_blank\" href=\"http://foo.com/more_(than)_one_(parens)\" title=\"http://foo.com/more_(than)_one_(parens)\">http://foo.com/more_(than)_one_(parens)</a>", result);
            }
Ejemplo n.º 23
0
            public void UrlWithSingleTrailingParanthesisMatchesCloseBracketAsText()
            {
                // Arrange
                var message = "(message http://www.jabbr.net/) doesn't match the outside brackets";
                HashSet <string> extractedUrls;

                // Act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                // Assert
                Assert.Equal("(message <a rel=\"nofollow external\" target=\"_blank\" href=\"http://www.jabbr.net/\" title=\"http://www.jabbr.net/\">http://www.jabbr.net/</a>) doesn't match the outside brackets", result);
            }
Ejemplo n.º 24
0
            public void UrlsThatContainCommasAreEncodedEntirely()
            {
                // Arrange
                var message = @"found him, hes https://twitter.com/d,r,e,a,m,e,r,3, sent him a tweet";
                HashSet <string> extractedUrls;

                // Act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                // Assert
                Assert.Equal("found him, hes <a rel=\"nofollow external\" target=\"_blank\" href=\"https://twitter.com/d,r,e,a,m,e,r,3\" title=\"https://twitter.com/d,r,e,a,m,e,r,3\">https://twitter.com/d,r,e,a,m,e,r,3</a>, sent him a tweet", result);
            }
Ejemplo n.º 25
0
            public void UrlsFollowedByACommaDontEncodeTheComma()
            {
                // Arrange
                var message = @"found him, hes https://twitter.com/dreamer3, sent him a tweet";
                HashSet <string> extractedUrls;

                // Act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                // Assert
                Assert.Equal("found him, hes <a rel=\"nofollow external\" target=\"_blank\" href=\"https://twitter.com/dreamer3\" title=\"https://twitter.com/dreamer3\">https://twitter.com/dreamer3</a>, sent him a tweet", result);
            }
Ejemplo n.º 26
0
            public void LocalHost()
            {
                //arrange
                var message = @"http://localhost/foo";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("<a rel=\"nofollow external\" target=\"_blank\" href=\"http://localhost/foo\" title=\"http://localhost/foo\">http://localhost/foo</a>", result);
            }
Ejemplo n.º 27
0
            public void GoogleUrlWithQueryStringParams()
            {
                //arrange
                var message = "https://www.google.com/search?q=test+search&amp;sugexp=chrome,mod=14&amp;sourceid=chrome&amp;ie=UTF-8";
                HashSet <string> extractedUrls;

                //act
                var result = TextTransform.TransformAndExtractUrls(message, out extractedUrls);

                //assert
                Assert.Equal("<a rel=\"nofollow external\" target=\"_blank\" href=\"https://www.google.com/search?q=test+search&amp;sugexp=chrome,mod=14&amp;sourceid=chrome&amp;ie=UTF-8\" title=\"https://www.google.com/search?q=test+search&amp;sugexp=chrome,mod=14&amp;sourceid=chrome&amp;ie=UTF-8\">https://www.google.com/search?q=test+search&amp;sugexp=chrome,mod=14&amp;sourceid=chrome&amp;ie=UTF-8</a>", result);
                //Assert.Equal("<a rel=\"nofollow external\" target=\"_blank\" href=\"https://www.google.com/search?q=test+search&sugexp=chrome,mod=14&sourceid=chrome&ie=UTF-8\" title=\"https://www.google.com/search?q=test+search&amp;sugexp=chrome,mod=14&amp;sourceid=chrome&amp;ie=UTF-8\">https://www.google.com/search?q=test+search&amp;sugexp=chrome,mod=14&amp;sourceid=chrome&amp;ie=UTF-8</a>", result);
            }
Ejemplo n.º 28
0
        public override void ExecuteAdminOperation(CommandContext context, CallerContext callerContext, Models.ChatUser callingUser, string[] args)
        {
            string messageText = String.Join(" ", args).Trim();

            if (String.IsNullOrEmpty(messageText))
            {
                throw new InvalidOperationException("What did you want to broadcast?");
            }

            HashSet <string> urls;
            var transform = new TextTransform(context.Repository);

            messageText = transform.Parse(messageText);

            messageText = TextTransform.TransformAndExtractUrls(messageText, out urls);

            context.NotificationService.BroadcastMessage(callingUser, messageText);
        }
Ejemplo n.º 29
0
        private void HandleBroadcast(ChatUser user, string[] parts)
        {
            if (!user.IsAdmin)
            {
                throw new InvalidOperationException("You are not an admin.");
            }

            string messageText = String.Join(" ", parts.Skip(1)).Trim();

            if (String.IsNullOrEmpty(messageText))
            {
                throw new InvalidOperationException("What did you want to broadcast?");
            }

            HashSet <string> urls;
            var transform = new TextTransform(_repository);

            messageText = transform.Parse(messageText);

            messageText = TextTransform.TransformAndExtractUrls(messageText, out urls);

            _notificationService.BroadcastMessage(user, messageText);
        }