From 25a7c9d09dafb1373051e7eb7fbc43af09b3ae5b Mon Sep 17 00:00:00 2001 From: Jeff Putz Date: Wed, 11 Mar 2015 14:27:11 -0400 Subject: [PATCH] Text parser eats closing forum code for url tag when URL includes bang. Fixes #20. Also fixed unit tests for #19. --- .../Controllers/AccountControllerTests.cs | 16 ++++++++++------ .../TextParsingServiceForumCodeToHtmlTests.cs | 8 ++++++++ PopForums/Services/TextParsingService.cs | 2 +- Version.cs | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/PopForums.Test/Controllers/AccountControllerTests.cs b/PopForums.Test/Controllers/AccountControllerTests.cs index 5e7f7b86..a82e749a 100644 --- a/PopForums.Test/Controllers/AccountControllerTests.cs +++ b/PopForums.Test/Controllers/AccountControllerTests.cs @@ -378,7 +378,8 @@ public void ChangePasswordBadOldPassword() controller.ControllerContext = new ControllerContext(contextHelper.MockContext.Object, new RouteData(), controller); var user = UserTest.GetTestUser(); controller.SetUser(user); - _userService.Setup(u => u.VerifyPassword(user, It.IsAny())).Returns(false); + _userService.Setup(u => u.VerifyPassword(user, It.IsAny())).Returns(false); + _settingsManager.Setup(x => x.Current.IsNewUserApproved).Returns(true); var result = controller.ChangePassword(new UserEditSecurity { OldPassword = "no" }); Assert.IsNotNullOrEmpty(result.ViewData["PasswordResult"].ToString()); Assert.AreNotEqual("EditAccountNoUser", result.ViewName); @@ -392,8 +393,9 @@ public void ChangePasswordNoMatch() var contextHelper = new HttpContextHelper(); controller.ControllerContext = new ControllerContext(contextHelper.MockContext.Object, new RouteData(), controller); var user = UserTest.GetTestUser(); - controller.SetUser(user); - _userService.Setup(u => u.VerifyPassword(user, It.IsAny())).Returns(true); + controller.SetUser(user); + _userService.Setup(u => u.VerifyPassword(user, It.IsAny())).Returns(true); + _settingsManager.Setup(x => x.Current.IsNewUserApproved).Returns(true); var result = controller.ChangePassword(new UserEditSecurity{ NewPassword = "blah", NewPasswordRetype = "blah2"}); Assert.IsNotNullOrEmpty(result.ViewData["PasswordResult"].ToString()); Assert.AreNotEqual("EditAccountNoUser", result.ViewName); @@ -410,7 +412,8 @@ public void ChangePasswordFailsRules() controller.SetUser(user); _userService.Setup(u => u.VerifyPassword(user, It.IsAny())).Returns(true); _userService.Setup(u => u.IsPasswordValid(It.IsAny(), It.IsAny())).Returns(false).Callback((p, m) => m.AddModelError("Password", "whatever")); - var password = "awesome"; + var password = "awesome"; + _settingsManager.Setup(x => x.Current.IsNewUserApproved).Returns(true); var result = controller.ChangePassword(new UserEditSecurity { NewPassword = password, NewPasswordRetype = password }); Assert.IsNotNullOrEmpty(result.ViewData["PasswordResult"].ToString()); Assert.AreNotEqual("EditAccountNoUser", result.ViewName); @@ -427,8 +430,9 @@ public void ChangePasswordMatchAndValid() var user = UserTest.GetTestUser(); controller.SetUser(user); _userService.Setup(u => u.VerifyPassword(user, It.IsAny())).Returns(true); - _userService.Setup(u => u.IsPasswordValid(It.IsAny(), It.IsAny())).Returns(true); - var password = "awesome"; + _userService.Setup(u => u.IsPasswordValid(It.IsAny(), It.IsAny())).Returns(true); + var password = "awesome"; + _settingsManager.Setup(x => x.Current.IsNewUserApproved).Returns(true); var result = controller.ChangePassword(new UserEditSecurity { NewPassword = password, NewPasswordRetype = password }); Assert.IsNotNullOrEmpty(result.ViewData["PasswordResult"].ToString()); Assert.AreNotEqual("EditAccountNoUser", result.ViewName); diff --git a/PopForums.Test/Services/TextParsingServiceForumCodeToHtmlTests.cs b/PopForums.Test/Services/TextParsingServiceForumCodeToHtmlTests.cs index c7172442..3f65fee0 100644 --- a/PopForums.Test/Services/TextParsingServiceForumCodeToHtmlTests.cs +++ b/PopForums.Test/Services/TextParsingServiceForumCodeToHtmlTests.cs @@ -352,6 +352,14 @@ public void YouTubeTagConvertedToIframe() _settings.AllowImages = true; var result = service.ForumCodeToHtml("test test [youtube=http://www.youtube.com/watch?v=NL125lBWYc4] test"); Assert.AreEqual("

test test test

", result); + } + + [Test] + public void UrlWithBangParsesCorrectly() + { + var service = GetService(); + var result = service.ForumCodeToHtml("(and [url=\"https://groups.google.com/forum/#!original/rec.roller-coaster/iwTIvU2IXKI/hKB_D9uRbaEJ\"]'millennium' is spelled with two n's[/url] regardless of whether the new one starts in 2000 or 2001.)"); + Assert.AreEqual("

(and 'millennium' is spelled with two n's regardless of whether the new one starts in 2000 or 2001.)

", result); } } } \ No newline at end of file diff --git a/PopForums/Services/TextParsingService.cs b/PopForums/Services/TextParsingService.cs index 4ffebc93..3fe3d848 100644 --- a/PopForums/Services/TextParsingService.cs +++ b/PopForums/Services/TextParsingService.cs @@ -17,7 +17,7 @@ public TextParsingService(ISettingsManager settingsManager) private ISettingsManager _settingsManager; public static string[] AllowedCloseableTags = {"b", "i", "code", "pre", "ul", "ol", "li", "url", "quote", "img"}; - private readonly static Regex _tagPattern = new Regex(@"\[[\w""\?=&/;\+%\*\:~,\.\-\$\|@#]+\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private readonly static Regex _tagPattern = new Regex(@"\[[\w""\?=&/;\+%\*\:~,\!\.\-\$\|@#]+\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); private readonly static Regex _tagID = new Regex(@"\[/?(\w+)\=*.*?\]", RegexOptions.Compiled | RegexOptions.IgnoreCase); private readonly static Regex _protocolPattern = new Regex(@"(?=])(((news|(ht|f)tp(s?))\://)[\w\-\*]+(\.[\w\-/~\*]+)*/?)([\w\?=&/;\+%\*\:~,\.\-\$\|@#])*", RegexOptions.Compiled | RegexOptions.IgnoreCase); private readonly static Regex _wwwPattern = new Regex(@"(?