class TestInlineParser_parse_ref

Public Instance Methods

ok(e, str) click to toggle source
# File vendor/qwik/lib/qwik/parser-inline.rb, line 193
def ok(e, str)
  ok_eq(e, Qwik::InlineParser.parse_ref(str))
end
test_all() click to toggle source
# File vendor/qwik/lib/qwik/parser-inline.rb, line 197
def test_all
  # normal ref
  ok([:a, {:href=>'t.html'}, 't'], 't')
  ok([:a, {:href=>'http://e.com/'}, 'http://e.com/'], 'http://e.com/')

  # with title
  ok([:a, {:href=>'t.html'}, 's'], 's|t')
  ok([:a, {:href=>'http://e.com/'}, 's'], 's|http://e.com/')

  # interwiki
  ok([:plugin, {:param=>'s:t', :method=>'interwiki'}, 's:t'], 's:t')
  ok([:plugin, {:param=>'s:t', :method=>'interwiki'}, 'foo'], 'foo|s:t')

  # test_plugin_ref
  ok([:a, {:href=>'.attach'}, '.attach'], '.attach')
  ok([:a, {:href=>'.attach/t.txt'}, '.attach/t.txt'], '.attach/t.txt')
  ok([:a, {:href=>'.attach/s t.txt'}, '.attach/s t.txt'],
     '.attach/s t.txt')

  # test_img
  ok([:img, {:alt=>'http://e.com/t.jpg', :src=>'http://e.com/t.jpg'}],
     'http://e.com/t.jpg')
  ok([:img, {:alt=>'s', :src=>'http://e.com/t.jpg'}],
     's|http://e.com/t.jpg')

  # test security
  ok([:a, {:href=>"&{alert('hello');};.html"}, "&{alert('hello');};"],
     "&{alert('hello');};")

  # test_sjis_bug
  ok_eq("\203|\203X", 'ポス')
  ok([:a, {:href=>"\203|\203X.html"}, "\203|\203X"], 'ポス')

  # test_bug
  ok_eq("\226]", '望')
  ok([:a, {:href=>"\226].html"}, "\226]"], '望')

  # abnormal cases
  ok([:a, {:href=>'|.html'}, '|'],      '|')
  ok([:a, {:href=>'|.html'}, '|'],      '||')
  ok([:a, {:href=>'||.html'}, '||'],    '|||')
  ok([:a, {:href=>'s|.html'}, 's|'],    's|')
  ok([:a, {:href=>'s.html'},  's'],    '|s')
  ok([:a, {:href=>'http://example.com'}, 'http://example.com'],    '|http://example.com')
  ok([:plugin, {:param=>'s:t', :method=>'interwiki'}, 's:t'], '|s:t')
end