@parser.parse('[[foo bar]]').should == %Q{<p><a href="/wiki/foo%20bar">foo bar</a></p>\n}
end
+ it 'should trim leading whitespace' do
+ @parser.parse('[[ foo]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n}
+ @parser.parse('[[ foo]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n}
+ @parser.parse('[[ foo]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n}
+ @parser.parse('[[ foo]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n}
+ end
+
+ it 'should trim trailing whitespace' do
+ @parser.parse('[[foo ]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n}
+ @parser.parse('[[foo ]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n}
+ @parser.parse('[[foo ]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n}
+ @parser.parse('[[foo ]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n} # was a bug (exception)
+ @parser.parse('[[foo ]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n} # was a bug (crash)
+ end
+
+ it 'should trim leading and trailing whitespace (combined)' do
+ @parser.parse('[[ foo ]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n}
+ @parser.parse('[[ foo ]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n}
+ @parser.parse('[[ foo ]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n}
+ @parser.parse('[[ foo ]]').should == %Q{<p><a href="/wiki/foo">foo</a></p>\n}
+ end
+
+ it 'should leave embedded whitespace intact' do
+ @parser.parse('[[ foo bar ]]').should == %Q{<p><a href="/wiki/foo%20bar">foo bar</a></p>\n}
+ @parser.parse('[[foo bar ]]').should == %Q{<p><a href="/wiki/foo%20bar">foo bar</a></p>\n}
+ @parser.parse('[[ foo bar ]]').should == %Q{<p><a href="/wiki/foo%20bar">foo bar</a></p>\n}
+ end
+
it 'should encode and sanitize quotes' do
# note how percent encoding is used in the href, and named entities in the link text
@parser.parse('[[hello "world"]]').should == %Q{<p><a href="/wiki/hello%20%22world%22">hello "world"</a></p>\n}
it 'should rollback and show the unterminated link' do
@parser.parse('[[foo').should == %Q{<p>[[foo</p>\n}
end
+
+ it 'should not trim leading whitespace when rolling back' do
+ @parser.parse('[[ foo').should == %Q{<p>[[ foo</p>\n}
+ @parser.parse('[[ foo').should == %Q{<p>[[ foo</p>\n}
+ @parser.parse('[[ foo').should == %Q{<p>[[ foo</p>\n}
+ @parser.parse('[[ foo').should == %Q{<p>[[ foo</p>\n}
+ end
+
+ it 'should not trim trailing whitespace when rolling back' do
+ @parser.parse('[[foo ').should == %Q{<p>[[foo </p>\n}
+ @parser.parse('[[foo ').should == %Q{<p>[[foo </p>\n}
+ @parser.parse('[[foo ').should == %Q{<p>[[foo </p>\n}
+ @parser.parse('[[foo ').should == %Q{<p>[[foo </p>\n}
+ end
+
+ it 'should not trim leadig and trailing whitespace (combined) when rolling back' do
+ @parser.parse('[[ foo ').should == %Q{<p>[[ foo </p>\n}
+ @parser.parse('[[ foo ').should == %Q{<p>[[ foo </p>\n}
+ @parser.parse('[[ foo ').should == %Q{<p>[[ foo </p>\n}
+ @parser.parse('[[ foo ').should == %Q{<p>[[ foo </p>\n}
+ end
end
describe 'unterminated link targets (end-of-line)' do
it 'should rollback and show the unterminated link' do
@parser.parse("[[foo\n").should == %Q{<p>[[foo</p>\n}
end
+
+ it 'should not trim leading whitespace when rolling back' do
+ @parser.parse("[[ foo\n").should == %Q{<p>[[ foo</p>\n}
+ @parser.parse("[[ foo\n").should == %Q{<p>[[ foo</p>\n}
+ @parser.parse("[[ foo\n").should == %Q{<p>[[ foo</p>\n}
+ @parser.parse("[[ foo\n").should == %Q{<p>[[ foo</p>\n}
+ end
+
+ it 'should not trim trailing whitespace when rolling back' do
+ @parser.parse("[[foo \n").should == %Q{<p>[[foo </p>\n}
+ @parser.parse("[[foo \n").should == %Q{<p>[[foo </p>\n}
+ @parser.parse("[[foo \n").should == %Q{<p>[[foo </p>\n}
+ @parser.parse("[[foo \n").should == %Q{<p>[[foo </p>\n}
+ end
+
+ it 'should not trim leading and trailing whitespace (combined) when rolling back' do
+ @parser.parse("[[ foo \n").should == %Q{<p>[[ foo </p>\n}
+ @parser.parse("[[ foo \n").should == %Q{<p>[[ foo </p>\n}
+ @parser.parse("[[ foo \n").should == %Q{<p>[[ foo </p>\n}
+ @parser.parse("[[ foo \n").should == %Q{<p>[[ foo </p>\n}
+ end
end
describe 'missing link text' do
Wikitext::Parser.encode_link_target(' hello world').should == 'hello%20world'
Wikitext::Parser.encode_link_target(' hello world').should == 'hello%20world'
Wikitext::Parser.encode_link_target(' hello world').should == 'hello%20world'
+ Wikitext::Parser.encode_link_target(' hello world').should == 'hello%20world'
+ Wikitext::Parser.encode_link_target(' hello world').should == 'hello%20world'
end
it 'should eat trailing spaces' do
Wikitext::Parser.encode_link_target('hello world ').should == 'hello%20world'
Wikitext::Parser.encode_link_target('hello world ').should == 'hello%20world'
Wikitext::Parser.encode_link_target('hello world ').should == 'hello%20world'
+ Wikitext::Parser.encode_link_target('hello world ').should == 'hello%20world'
+ Wikitext::Parser.encode_link_target('hello world ').should == 'hello%20world'
end
it 'should eat leading and trailing spaces combined' do
- Wikitext::Parser.encode_link_target(' hello world ').should == 'hello%20world'
- Wikitext::Parser.encode_link_target(' hello world ').should == 'hello%20world'
- Wikitext::Parser.encode_link_target(' hello world ').should == 'hello%20world'
- Wikitext::Parser.encode_link_target(' hello world ').should == 'hello%20world'
+ Wikitext::Parser.encode_link_target(' hello world ').should == 'hello%20world'
+ Wikitext::Parser.encode_link_target(' hello world ').should == 'hello%20world'
+ Wikitext::Parser.encode_link_target(' hello world ').should == 'hello%20world'
+ Wikitext::Parser.encode_link_target(' hello world ').should == 'hello%20world'
+ Wikitext::Parser.encode_link_target(' hello world ').should == 'hello%20world'
+ Wikitext::Parser.encode_link_target(' hello world ').should == 'hello%20world'
end
it 'should return nothing for input consisting entirely of spaces' do
Wikitext::Parser.encode_link_target(' ').should == ''
Wikitext::Parser.encode_link_target(' ').should == ''
Wikitext::Parser.encode_link_target(' ').should == ''
+ Wikitext::Parser.encode_link_target(' ').should == ''
+ Wikitext::Parser.encode_link_target(' ').should == ''
end
it 'should convert reserved symbols into percent escapes' do
Wikitext::Parser.sanitize_link_target(' hello world').should == 'hello world'
Wikitext::Parser.sanitize_link_target(' hello world').should == 'hello world'
Wikitext::Parser.sanitize_link_target(' hello world').should == 'hello world'
+ Wikitext::Parser.sanitize_link_target(' hello world').should == 'hello world'
+ Wikitext::Parser.sanitize_link_target(' hello world').should == 'hello world'
end
it 'should eat trailing spaces' do
Wikitext::Parser.sanitize_link_target('hello world ').should == 'hello world'
Wikitext::Parser.sanitize_link_target('hello world ').should == 'hello world'
Wikitext::Parser.sanitize_link_target('hello world ').should == 'hello world'
+ Wikitext::Parser.sanitize_link_target('hello world ').should == 'hello world' # was a crasher
+ Wikitext::Parser.sanitize_link_target('hello world ').should == 'hello world' # was a crasher
+
+ # same but with lots of entities to force a reallocation (we were crashing under reallocation)
+ expected = '""""""""""'
+ Wikitext::Parser.sanitize_link_target('"""""""""" ').should == expected
end
it 'should eat leading and trailing spaces combined' do
- Wikitext::Parser.sanitize_link_target(' hello world ').should == 'hello world'
- Wikitext::Parser.sanitize_link_target(' hello world ').should == 'hello world'
- Wikitext::Parser.sanitize_link_target(' hello world ').should == 'hello world'
- Wikitext::Parser.sanitize_link_target(' hello world ').should == 'hello world'
+ Wikitext::Parser.sanitize_link_target(' hello world ').should == 'hello world'
+ Wikitext::Parser.sanitize_link_target(' hello world ').should == 'hello world'
+ Wikitext::Parser.sanitize_link_target(' hello world ').should == 'hello world'
+ Wikitext::Parser.sanitize_link_target(' hello world ').should == 'hello world'
+ Wikitext::Parser.sanitize_link_target(' hello world ').should == 'hello world'
+ Wikitext::Parser.sanitize_link_target(' hello world ').should == 'hello world'
end
it 'should return nothing for input consisting entirely of spaces' do
Wikitext::Parser.sanitize_link_target(' ').should == ''
Wikitext::Parser.sanitize_link_target(' ').should == ''
Wikitext::Parser.sanitize_link_target(' ').should == ''
+ Wikitext::Parser.sanitize_link_target(' ').should == ''
+ Wikitext::Parser.sanitize_link_target(' ').should == ''
end
it 'should convert double quotes into named entities' do