Skip to content

Commit 7edf4f3

Browse files
committed
Revert "Ignore YouTube URLs that are inline with text"
This reverts commit 0854c4c.
1 parent 5c3f557 commit 7edf4f3

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

lib/auto_html/youtube.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ def call(text)
2525

2626
def youtube_pattern
2727
@youtube_pattern ||=
28-
%r{^
29-
(https://)?
28+
%r{
29+
(https?://)?
3030
(www.)?
3131
(
3232
youtube\.com/watch\?v=|
3333
youtu\.be/|
3434
youtube\.com/watch\?feature=player_embedded&v=
3535
)
3636
([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?
37-
$
3837
}x
3938
end
4039

spec/auto_html/youtube_spec.rb

+13-26
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,37 @@
44

55
RSpec.describe AutoHtml::YouTube do
66
it 'transforms youtube url' do
7-
result = subject.call('https://www.youtube.com/watch?v=BwNrmYRiX_o')
7+
result = subject.call('http://www.youtube.com/watch?v=BwNrmYRiX_o')
88
expect(result).to eq '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen="yes"></iframe></div>'
99
end
1010

11-
it 'transforms youtube url in its own paragraph' do
12-
result = subject.call(%(Text above
13-
14-
https://www.youtube.com/watch?v=BwNrmYRiX_o
15-
16-
Text below))
17-
expect(result).to eq %(Text above
18-
19-
<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen="yes"></iframe></div>
20-
21-
Text below)
22-
end
23-
2411
it 'transforms youtube url with lot of params' do
25-
result = subject.call('https://www.youtube.com/watch?v=BwNrmYRiX_o&eurl=http%3A%2F%2Fvukajlija.com%2Fvideo%2Fklipovi%3Fstrana%3D6&feature=player_embedded') { youtube }
12+
result = subject.call('http://www.youtube.com/watch?v=BwNrmYRiX_o&eurl=http%3A%2F%2Fvukajlija.com%2Fvideo%2Fklipovi%3Fstrana%3D6&feature=player_embedded') { youtube }
2613
expect(result).to eq '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen="yes"></iframe></div>'
2714
end
2815

29-
it 'does not transform inline YouTube URL' do
30-
result = subject.call('inline https://www.youtube.com/watch?v=fT1ahr81HLw is ignored') { youtube }
31-
expect(result).to eq 'inline https://www.youtube.com/watch?v=fT1ahr81HLw is ignored'
16+
it 'transforms youtube url ignoring text' do
17+
result = subject.call('foo http://www.youtube.com/watch?v=fT1ahr81HLw bar') { youtube }
18+
expect(result).to eq 'foo <div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/fT1ahr81HLw" frameborder="0" allowfullscreen="yes"></iframe></div> bar'
19+
end
20+
21+
it 'transforms youtube url ignoring html tags' do
22+
result = subject.call('foo http://www.youtube.com/watch?v=fT1ahr81HLw<br>bar') { youtube }
23+
expect(result).to eq 'foo <div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/fT1ahr81HLw" frameborder="0" allowfullscreen="yes"></iframe></div><br>bar'
3224
end
3325

3426
it 'transforms url without www' do
35-
result = subject.call('https://youtube.com/watch?v=BwNrmYRiX_o') { youtube }
27+
result = subject.call('http://youtube.com/watch?v=BwNrmYRiX_o') { youtube }
3628
expect(result).to eq '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen="yes"></iframe></div>'
3729
end
3830

3931
it 'transforms short url' do
40-
result = subject.call('https://www.youtu.be/BwNrmYRiX_o')
32+
result = subject.call('http://www.youtu.be/BwNrmYRiX_o')
4133
expect(result).to eq '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/BwNrmYRiX_o" frameborder="0" allowfullscreen="yes"></iframe></div>'
4234
end
4335

4436
it 'transforms short url with params' do
45-
result = subject.call('https://youtu.be/t7NdBIA4zJg?t=1s&hd=1')
37+
result = subject.call('http://youtu.be/t7NdBIA4zJg?t=1s&hd=1')
4638
expect(result).to eq '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/t7NdBIA4zJg" frameborder="0" allowfullscreen="yes"></iframe></div>'
4739
end
4840

@@ -55,9 +47,4 @@
5547
result = subject.call('www.youtube.com/watch?v=t7NdBIA4zJg')
5648
expect(result).to eq '<div class="video youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/t7NdBIA4zJg" frameborder="0" allowfullscreen="yes"></iframe></div>'
5749
end
58-
59-
it 'ignores url inside <pre> tag' do
60-
result = subject.call('<pre>https://www.youtube.com/watch?v=fT1ahr81HLw</pre>') { youtube }
61-
expect(result).to eq '<pre>https://www.youtube.com/watch?v=fT1ahr81HLw</pre>'
62-
end
6350
end

0 commit comments

Comments
 (0)