public void Internal_Links_Should_Resolve_With_Id() { // Bug #87 // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; UrlResolverMock resolver = new UrlResolverMock(); resolver.InternalUrl = "blah"; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); converter.UrlResolver = resolver; string markdownText = "[Link](My-first-page)"; string invalidMarkdownText = "[Link](My first page)"; // Act string expectedHtml = "<p><a href=\"blah\">Link</a></p>\n"; string expectedInvalidLinkHtml = "<p>[Link](My first page)</p>\n"; string actualHtml = converter.ToHtml(markdownText); string actualHtmlInvalidLink = converter.ToHtml(invalidMarkdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); Assert.That(actualHtmlInvalidLink, Is.EqualTo(expectedInvalidLinkHtml)); }
public void Code_Blocks_Should_Allow_Quotes() { // Issue #82 // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); string markdownText = "Here is some `// code with a 'quote' in it and another \"quote\"`\n\n" + " var x = \"some tabbed code\";\n\n"; // 2 line breaks followed by 4 spaces (tab stop) at the start indicates a code block string expectedHtml = "<p>Here is some <code>// code with a 'quote' in it and another \"quote\"</code></p>\n\n" + "<pre><code>var x = \"some tabbed code\";\n" + "</code></pre>\n"; // Act string actualHtml = converter.ToHtml(markdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Attachment_Link_Should_Not_Have_NoFollow_Attribute() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"/Attachments/folder/myfile.jpg\">Some link text</a> <a href=\"/Attachments/folder2/myfile.jpg\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[~/folder/myfile.jpg|Some link text]] [[attachment:/folder2/myfile.jpg|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void External_Links_With_Anchor_Tag_Should_Retain_The_Anchor() { // Issue #172 // Arrange _repository.SiteSettings.MarkupType = "Creole"; _repository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"http://www.google.com/?blah=xyz#myanchor\" class=\"external-link\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.google.com/?blah=xyz#myanchor|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Html_Should_Not_Be_Sanitized_If_UseHtmlWhiteList_Setting_Is_False() { // Arrange _applicationSettings.UseHtmlWhiteList = false; _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string htmlFragment = "<div onclick=\"javascript:alert('ouch');\">test</div>"; MarkupConverter converter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); // Act string actualHtml = converter.ToHtml(htmlFragment); // Assert string expectedHtml = "<p>" + htmlFragment + "\n</p>"; Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void imageparsed_should_convert_to_absolute_path() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Markdown"; UrlResolverMock resolver = new UrlResolverMock(); resolver.AbsolutePathSuffix = "123"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); _markupConverter.UrlResolver = resolver; // Act bool wasCalled = false; _markupConverter.Parser.ImageParsed += (object sender, ImageEventArgs e) => { wasCalled = (e.Src == "/Attachments/DSC001.jpg123"); }; _markupConverter.ToHtml("![Image title](/DSC001.jpg)"); // Assert Assert.True(wasCalled, "ImageParsed.ImageEventArgs.Src did not match."); }
public void specialurl_link_should_not_have_nofollow_attribute() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/Special:Random\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[Special:Random|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void internal_wiki_page_link_should_not_have_nofollow_attribute() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _pageRepository.AddNewPage(new Page() { Id = 1, Title = "foo-page" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/1/foo-page\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[foo-page|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void links_to_named_anchors_should_not_have_external_css_class() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"#myanchortag\">hello world</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[#myanchortag|hello world]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Links_With_The_Word_Script_In_Url_Should_Not_Be_Cleaned() { // Issue #159 // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.descriptionattribute.aspx\">ComponentModel.Description</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://msdn.microsoft.com/en-us/library/system.componentmodel.descriptionattribute.aspx|ComponentModel.Description]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void links_starting_with_http_www_mailto_tag_are_no_rewritten_as_internal() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"http://www.blah.com\" class=\"external-link\">link1</a> <a rel=\"nofollow\" href=\"www.blah.com\" class=\"external-link\">link2</a> <a rel=\"nofollow\" href=\"mailto:spam@gmail.com\" class=\"external-link\">spam</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.blah.com|link1]] [[www.blah.com|link2]] [[mailto:[email protected]|spam]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void links_starting_with_attachmentcolon_should_resolve_as_attachment_paths() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/Attachments/my/folder/image1.jpg\">hello world</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[attachment:/my/folder/image1.jpg|hello world]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void links_with_the_word_script_in_url_should_not_be_cleaned() { // Issue #159 // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.descriptionattribute.aspx\" class=\"external-link\">ComponentModel.Description</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://msdn.microsoft.com/en-us/library/system.componentmodel.descriptionattribute.aspx|ComponentModel.Description]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Links_With_Dashes_Or_23_Are_Rewritten_And_Not_Parsed_As_Encoded_Hashes() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"#myanchortag\">hello world</a> <a href=\"https://www.google.com/some-page-23\">google</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[#myanchortag|hello world]] [[https://www.google.com/some-page-23|google]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Links_To_Named_Anchors_Should_Not_Have_External_CSS_Class() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"#myanchortag\">hello world</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[#myanchortag|hello world]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Links_Starting_With_Tilde_Should_Resolve_As_Attachment_Paths() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"/Attachments/my/folder/image1.jpg\">hello world</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[~/my/folder/image1.jpg|hello world]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Links_Starting_With_Https_Or_Hash_Are_Not_Rewritten_As_Internal() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"#myanchortag\">hello world</a> <a rel=\"nofollow\" href=\"https://www.google.com\" class=\"external-link\">google</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[#myanchortag|hello world]] [[https://www.google.com|google]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void Internal_Links_With_Anchor_Tag_Should_Retain_The_Anchor() { // Issue #172 // Arrange _repository.SiteSettings.MarkupType = "Creole"; _repository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/1/foo#myanchor\">Some link text</a>\n</p>"; // use /index/ as no routing exists // Act string actualHtml = _markupConverter.ToHtml("[[foo#myanchor|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Images_Should_Support_Dimensions_And_Titles() { // Arrange Page page = new Page() { Id = 1, Title = "My first page" }; RepositoryMock repositoryStub = new RepositoryMock(); repositoryStub.AddNewPage(page, "My first page", "admin", DateTime.UtcNow); repositoryStub.SiteSettings = new SiteSettings() { MarkupType = "Markdown" }; ApplicationSettings settings = new ApplicationSettings(); settings.Installed = true; settings.UpgradeRequired = false; MarkupConverter converter = new MarkupConverter(settings, repositoryStub, _pluginFactory); string markdownText = "Here is an image with a title:![Image](/Image1.png \"Image\") \n\n" + "And another with equal dimensions ![Square](/Image1.png \"Square\" =250x) \n\n" + "And this one is a rectangle ![Rectangle](/Image1.png \"Rectangle\" =250x350)"; string expectedHtml = "<p>Here is an image with a title:<img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Image\" width=\"\" height=\"\" title=\"Image\" /> </p>\n\n" + "<p>And another with equal dimensions <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Square\" width=\"250px\" height=\"\" title=\"Square\" /> </p>\n\n" + "<p>And this one is a rectangle <img src=\"/Attachments/Image1.png\" border=\"0\" alt=\"Rectangle\" width=\"250px\" height=\"350px\" title=\"Rectangle\" /></p>\n"; // Act string actualHtml = converter.ToHtml(markdownText); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void internal_links_with_urlencoded_anchor_tag_should_retain_the_anchor() { // Issue #172 // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _pageRepository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/1/foo%23myanchor\">Some link text</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[foo%23myanchor|Some link text]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void internal_links_with_anchor_tag_should_retain_the_anchor_with_markdown() { // Issue #172 // Arrange _settingsRepository.SiteSettings.MarkupType = "Markdown"; _pageRepository.AddNewPage(new Page() { Id = 1, Title = "foo" }, "foo", "admin", DateTime.Today); _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/1/foo#myanchor\">Some link text</a></p>\n"; // use /index/ as no routing exists // Act string actualHtml = _markupConverter.ToHtml("[Some link text](foo#myanchor)"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Links_With_Angle_Brackets_And_Quotes_Should_Be_Encoded() { // Issue #159 // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"http://www.google.com/">javascript:alert('hello')\">ComponentModel</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.google.com/\">javascript:alert('hello')|ComponentModel]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void links_with_angle_brackets_and_quotes_should_be_encoded() { // Issue #159 // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"http://www.google.com/">javascript:alert('hello')\" class=\"external-link\">ComponentModel</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.google.com/\">javascript:alert('hello')|ComponentModel]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void Links_Starting_With_Http_Www_Mailto_Tag_Are_No_Rewritten_As_Internal() { // Arrange _repository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _repository, _pluginFactory); string expectedHtml = "<p><a href=\"http://www.blah.com\">link1</a> <a href=\"www.blah.com\">link2</a> <a href=\"mailto:spam@gmail.com\">spam</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[http://www.blah.com|link1]] [[www.blah.com|link2]] [[mailto:[email protected]|spam]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void links_starting_with_specialcolon_should_resolve_as_full_specialpage() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a href=\"/wiki/Special:Foo\">My special page</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[Special:Foo|My special page]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml), actualHtml); }
public void links_with_dashes_or_23_are_rewritten_and_not_parsed_as_encoded_hashes() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string expectedHtml = "<p><a rel=\"nofollow\" href=\"#myanchortag\">hello world</a> <a rel=\"nofollow\" href=\"https://www.google.com/some-page-23\" class=\"external-link\">google</a>\n</p>"; // Act string actualHtml = _markupConverter.ToHtml("[[#myanchortag|hello world]] [[https://www.google.com/some-page-23|google]]"); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }
public void should_not_render_toc_with_multiple_curlies() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); _markupConverter.UrlResolver = new UrlResolverMock(); string htmlFragment = "Give me a {{TOC}} and a {{{TOC}}} - the should not render a TOC"; string expected = @"<p>Give me a <div class=""floatnone""><div class=""image_frame""><img src=""/Attachments/TOC""></div></div> and a TOC - the should not render a TOC" + "\n</p>"; // Act string actualHtml = _markupConverter.ToHtml(htmlFragment); // Assert Assert.That(actualHtml, Is.EqualTo(expected)); }
public PageViewModel(PageContent pageContent, MarkupConverter converter) { if (pageContent == null) throw new ArgumentNullException("pageContent"); if (pageContent.Page == null) throw new ArgumentNullException("pageContent.Page"); if (converter == null) throw new ArgumentNullException("converter"); Id = pageContent.Page.Id; Title = pageContent.Page.Title; PreviousTitle = pageContent.Page.Title; CreatedBy = pageContent.Page.CreatedBy; CreatedOn = pageContent.Page.CreatedOn; IsLocked = pageContent.Page.IsLocked; ModifiedBy = pageContent.Page.ModifiedBy; ModifiedOn = pageContent.Page.ModifiedOn; RawTags = pageContent.Page.Tags; Content = pageContent.Text; VersionNumber = pageContent.VersionNumber; PageHtml pageHtml = converter.ToHtml(pageContent.Text); ContentAsHtml = pageHtml.Html; IsCacheable = pageHtml.IsCacheable; PluginHeadHtml = pageHtml.HeadHtml; PluginFooterHtml = pageHtml.FooterHtml; PluginPreContainer = pageHtml.PreContainerHtml; PluginPostContainer = pageHtml.PostContainerHtml; CreatedOn = DateTime.SpecifyKind(CreatedOn, DateTimeKind.Utc); ModifiedOn = DateTime.SpecifyKind(ModifiedOn, DateTimeKind.Utc); AllTags = new List<TagViewModel>(); }
public void ImageParsed_Should_Not_Rewrite_Images_As_Internal_That_Start_With_Known_Prefixes(string imageUrl) { // Arrange _settingsRepository.SiteSettings.MarkupType = "Markdown"; UrlResolverMock resolver = new UrlResolverMock(); resolver.AbsolutePathSuffix = "123"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); _markupConverter.UrlResolver = resolver; bool wasCalled = false; _markupConverter.Parser.ImageParsed += (object sender, ImageEventArgs e) => { wasCalled = (e.Src == imageUrl); }; // Act _markupConverter.ToHtml("![Image title](" + imageUrl + ")"); // Assert Assert.True(wasCalled); }
public void should_remove_script_link_iframe_frameset_frame_applet_tags_from_text() { // Arrange _settingsRepository.SiteSettings.MarkupType = "Creole"; _markupConverter = new MarkupConverter(_applicationSettings, _settingsRepository, _pageRepository, _pluginFactory); string markdown = " some text <script type=\"text/html\">while(true)alert('lolz');</script>" + "<iframe src=\"google.com\"></iframe><frame>blah</frame> <applet code=\"MyApplet.class\" width=100 height=140></applet>" + "<frameset src='new.html'></frameset>"; string expectedHtml = "<p> some text blah \n</p>"; // Act string actualHtml = _markupConverter.ToHtml(markdown); // Assert Assert.That(actualHtml, Is.EqualTo(expectedHtml)); }