return string_from_str(parser.link_target);
}
-// this method exposed for testing only
-VALUE Wikitext_parser_encode_special_link_target(VALUE self, VALUE in)
-{
- parser_t parser;
- parser.space_to_underscore = false;
- parser.link_target = str_new_from_string(in);
- GC_WRAP_STR(parser.link_target, link_target_gc);
- _Wikitext_encode_link_target(&parser);
- return string_from_str(parser.link_target);
-}
-
// returns 1 (true) if supplied string is blank (nil, empty, or all whitespace)
// returns 0 (false) otherwise
bool _Wikitext_blank(str_t *str)
VALUE Wikitext_parser_encode_link_target(VALUE self, VALUE in);
-VALUE Wikitext_parser_encode_special_link_target(VALUE self, VALUE in);
-
VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self);
VALUE Wikitext_parser_profiling_parse(VALUE self, VALUE string);
rb_define_method(cWikitextParser, "fulltext_tokenize", Wikitext_parser_fulltext_tokenize, -1);
rb_define_singleton_method(cWikitextParser, "sanitize_link_target", Wikitext_parser_sanitize_link_target, 1);
rb_define_singleton_method(cWikitextParser, "encode_link_target", Wikitext_parser_encode_link_target, 1);
- rb_define_singleton_method(cWikitextParser, "encode_special_link_target", Wikitext_parser_encode_special_link_target, 1);
rb_define_attr(cWikitextParser, "line_ending", Qtrue, Qtrue);
rb_define_attr(cWikitextParser, "internal_link_prefix", Qtrue, Qtrue);
rb_define_attr(cWikitextParser, "img_prefix", Qtrue, Qtrue);
Wikitext::Parser.encode_link_target(string).should == URI.escape(string, reserved).downcase
end
end
-
- # "special" links don't get transformed in any way
- describe 'special links' do
-
- # as of version 1.4.0 the encode_link_target function no longer handles special links
- it 'should (no longer) recognize links which match /\A[a-z]+\/\d+\z/ as being special' do
- string = 'foo/10'
- Wikitext::Parser.encode_special_link_target(string).should == 'foo%2f10'
- Wikitext::Parser.encode_link_target(string).should == 'foo%2f10'
- end
-
- it "should not recognize links which don't match at /\A/ as being special" do
- string = ' foo/10'
- Wikitext::Parser.encode_special_link_target(string).should_not == string
- string = '..foo/10'
- Wikitext::Parser.encode_special_link_target(string).should_not == string
- string = '12foo/10'
- Wikitext::Parser.encode_special_link_target(string).should_not == string
- end
-
- it "should not recognize links which don't match at /\z/ as being special" do
- string = 'foo/10 '
- Wikitext::Parser.encode_special_link_target(string).should_not == string
- string = 'foo/10__'
- Wikitext::Parser.encode_special_link_target(string).should_not == string
- string = 'foo/10##'
- Wikitext::Parser.encode_special_link_target(string).should_not == string
- string = 'foo/10ab'
- Wikitext::Parser.encode_special_link_target(string).should_not == string
- end
-
- it "should not recognize links which don't match at /[a-z]/ (case differences) as being special" do
- string = 'FOO/10'
- Wikitext::Parser.encode_special_link_target(string).should_not == string
- end
-
- it "should not recognize links which don't match at /[0-9]/ (case differences) as being special" do
- string = 'foo/xx'
- Wikitext::Parser.encode_special_link_target(string).should_not == string
- end
-
- it "should not recognize links which don't match at /\// as being special" do
- string = 'foo 10'
- Wikitext::Parser.encode_special_link_target(string).should_not == string
- end
- end
end
-