From 6b9ad7c4c6ba2d1ceda4981966523ea46d9df968 Mon Sep 17 00:00:00 2001
From: Ilya Zhitomirskiy #{text} <script>alert('XSS is evil')</script> alert('XSS is evil')
"
- end
-
- def double_emphasis(text)
- "#{text}"
- end
-
- def linebreak()
- "\n#{text}
"
- end
-
- def link(link, title, content)
- #hax
- content ||=''
-
- return autolink(link, 'url') if link == content
-
- if link =~ Regexp.new(Regexp.escape(content))
- return autolink(link, 'url')
- end
-
- if link !~ %r{^\w+://}
- link = "http://#{link}"
- end
-
- tag = if title and content
- %Q{#{content}}
- elsif content
- %Q{#{content}}
- else
- autolink(link, 'url')
- end
- return tag
- end
-
- def paragraph(text)
- #hax again... why is markdownify passing us nil?
- text ||=''
-
- if @newlines
- br = linebreak
-
- # in very clear cases, let newlines become
tags
- # Grabbed from Github flavored Markdown
- text = text.gsub(/^[\w\<][^\n]*\n+/) do |x|
- x =~ /\n{2}/ ? x : (x = x.strip; x << br)
- end
- end
- return "puts "Hello"}
- message = %Q{~~~\nA\nB\n~~~\n}
- markdownify(message).should =~ %r{
}
- end
-
- it "doesn't double parse video links" do
- message = "http://www.vimeo.com/17449557
- http://www.youtube.com/watch?v=0x__dDWdf23&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1
- http://youtu.be/x_CzD0GBD-4"
- res = markdownify(message)
- res.should =~ /href.+href.+href/m
- res.should_not =~ /href.+href.+href.+href/m
- end
-
- describe "video links" do
- it "recognizes vimeo links" do
- video_id = "17449557"
- url = "http://www.vimeo.com/#{video_id}"
- res = markdownify(url)
- res.should =~ /data-host="vimeo.com"/
- res.should =~ /data-video-id="#{video_id}"/
- end
-
- it "matches a trailing slash in a vimeo link" do
- video_id = "17449557"
- url = "http://www.vimeo.com/#{video_id}/"
- res = markdownify(url)
- res.should =~ /data-host="vimeo.com"/
- res.should =~ /data-video-id="#{video_id}"/
- res.should_not =~ />\//
- end
-
- it "recognizes youtube links" do
- video_id = "0x__dDWdf23"
- url = "http://www.youtube.com/watch?v=" + video_id + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
- res = markdownify(url)
- res.should =~ /Youtube:/
- res.should =~ /data-host="youtube.com"/
- res.should =~ /data-video-id="#{video_id}"/
-
- url = "www.youtube.com/watch?foo=bar&v=BARFOO-----&whatever=related"
- res = markdownify(url)
- res.should =~ /Youtube:/
- res.should =~ /data-host="youtube.com"/
- res.should =~ /data-video-id="BARFOO-----"/
- end
-
- it "recognizes youtu.be links" do
- video_id = "x_CzD0GBD-4"
- url = "http://youtu.be/#{video_id}"
- res = markdownify(url)
- res.should =~ /Youtube:/
- res.should =~ /data-host="youtube.com"/
- res.should =~ /data-video-id="#{video_id}"/
- end
-
- it "recognizes youtube links with hyphens" do
- video_id = "ABYnqp-bxvg"
- url = "http://www.youtube.com/watch?v=" + video_id + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
- res = markdownify(url)
- res.should =~ /Youtube:/
- res.should =~ /data-host="youtube.com"/
- res.should =~ /data-video-id="#{video_id}"/
- end
-
- it "keeps anchors" do
- anchor = "#t=11m34"
- video_id = "DHRoHuv3I8E"
- url = "http://www.youtube.com/watch?v=" + video_id + anchor
- res = markdownify(url)
- res.should =~ /Youtube:/
- res.should =~ /data-host="youtube.com"/
- res.should =~ /data-video-id="#{video_id}"/
- res.should =~ /data-anchor="#{anchor}"/
- end
-
- it "has an empty data-anchor attribute if there is no anchor" do
- video_id = "DHRoHuv3I8E"
- url = "http://www.youtube.com/watch?v=" + video_id
- res = markdownify(url)
- res.should =~ /Youtube:/
- res.should =~ /data-host="youtube.com"/
- res.should =~ /data-video-id="#{video_id}"/
- res.should =~ /data-anchor=""/
- end
-
- it "leaves the links in the href of the #a tag" do
- video_id = "ABYnqp-bxvg"
- start_url ="http://www.youtube.com/watch?v=" + video_id
- url = start_url + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
- res = markdownify(url)
- res.should =~ /href=[\S]+v=#{video_id}/
- end
-
- it 'does not autolink inside the link' do
- video_id = "ABYnqp-bxvg"
- start_url ="http://www.youtube.com/watch?v=" + video_id
- url = start_url + "&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
- res = markdownify(url)
- res.match(/href=""+url+"\nA\nB\n
i ♥ you
" - end - - it "replaces various things with (their) HTML entities" do - message = "... <-> -> <- (tm) (r) (c)" - markdownify(message).should == "… ↔ → ← ™ ® ©
" - end - - it "skips doing it if you say so" do - message = "... -> <-" - markdownify(message, :specialchars => false).should == "... -> <-
" - end - end - - describe "weak emphasis" do - it "should be recognized (1/2)" do - message = "*some text* some text *some text* some text" - markdownify(message).should == "some text some text some text some text
" - end - - it "should be recognized (2/2)" do - message = "_some text_ some text _some text_ some text" - markdownify(message).should == "some text some text some text some text
" - end - end - - describe "strong emphasis" do - it "should be recognized (1/2)" do - message = "**some text** some text **some text** some text" - markdownify(message).should == "some text some text some text some text
" - end - - it "should be recognized (2/2)" do - message = "__some text__ some text __some text__ some text" - markdownify(message).should == "some text some text some text some text
" - end - end - - describe "nested weak and strong emphasis" do - it "should be rendered correctly" do - message = "__this is _some_ text__" - markdownify(message).should == "this is some text
" - message = "*this is **some** text*" - markdownify(message).should == "this is some text
" - message = "___some text___" - markdownify(message).should == "some text
" - end - end - - describe "links" do - it "should be recognized without title attribute" do - message = "[link text](http://someurl.com) [link text](http://someurl.com)" - markdownify(message).should == '' - end - - it "should be recognized with title attribute" do - message = '[link text](http://someurl.com "some title") [link text](http://someurl.com "some title")' - markdownify(message).should == '' - end - - it "should have a robust link parsing" do - message = "[wikipedia](http://en.wikipedia.org/wiki/Text_(literary_theory))" - link = markdownify(message) - link.should =~ %r{href="http://en.wikipedia.org/wiki/Text_%28literary_theory%29"} - - message = "[ links]( google.com)" - markdownify(message).should == %Q{} - - message = "[_http_](http://google.com/search?q=with_multiple__underscores*and**asterisks )" - markdownify(message).should == %Q{} - message = %{[___FTP___]( ftp://ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4 'File Transfer Protocol')} - markdownify(message).should == %{} - - message = %{[**any protocol**](foo://bar.example.org/yes_it*makes*no_sense)} - markdownify(message).should == %{} - - message = "This [ *text* ]( http://en.wikipedia.org/wiki/Text_(literary_theory) ) with many [ links]( google.com) tests [_http_](http://google.com/search?q=with_multiple__underscores*and**asterisks ), [___FTP___]( ftp://ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4 'File Transfer Protocol'), [**any protocol**](foo://bar.example.org/yes_it*makes*no_sense)" - markdownify(message).should == 'This text with many links tests http, FTP, any protocol
' - end - - end - - describe "nested emphasis and links tags" do - it "should be rendered correctly" do - message = '[**some *link* text**](someurl.com "some title")' - markdownify(message).should == '' - end - end - - it "should allow escaping" do - message = '*some text* \*some text* \**some text* _some text_ \_some text_ \__some text_' - markdownify(message).should == "some text *some text* *some text some text _some text_ _some text
" - end - - describe "newlines" do - it 'skips inserting newlines if you pass the newlines option' do - message = "These\nare\n\some\nnew\lines" - res = markdownify(message, :newlines => false) - res.should == "#{message}
" - end - - it 'generates breaklines' do - message = "These\nare\nsome\nnew\nlines" - res = markdownify(message) - res.should == "These
are
some
new
lines
Some text, then a line break and a link
joindiaspora.com
some more text