]> git.wincent.com - wikitext.git/commitdiff
Invert sense of "trim" parameter in _Wikitext_append_sanitized_link_target
authorWincent Colaiuta <win@wincent.com>
Mon, 11 May 2009 23:03:26 +0000 (01:03 +0200)
committerWincent Colaiuta <win@wincent.com>
Mon, 11 May 2009 23:03:26 +0000 (01:03 +0200)
Trim if "trim" is true; it makes more sense.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
ext/parser.c

index 55b47f62287389dfbfb906c621f63ac4d3578966..d54c1c711c5396085e7e76434516c37bfd328fe2 100644 (file)
@@ -743,8 +743,8 @@ void _Wikitext_trim_link_text(parser_t *parser)
 
 // - non-printable (non-ASCII) characters converted to numeric entities
 // - QUOT and AMP characters converted to named entities
 
 // - non-printable (non-ASCII) characters converted to numeric entities
 // - QUOT and AMP characters converted to named entities
-// - if trim is true, there is no special treatment of spaces
-// - if trim is false, leading and trailing whitespace trimmed
+// - if trim is true, leading and trailing whitespace trimmed
+// - if trim is false, there is no special treatment of spaces
 void _Wikitext_append_sanitized_link_target(parser_t *parser, str_t *output, bool trim)
 {
     char    *src        = parser->link_target->ptr;
 void _Wikitext_append_sanitized_link_target(parser_t *parser, str_t *output, bool trim)
 {
     char    *src        = parser->link_target->ptr;
@@ -780,7 +780,7 @@ void _Wikitext_append_sanitized_link_target(parser_t *parser, str_t *output, boo
         }
         else if (*src == '<' || *src == '>')
             rb_raise(rb_eRangeError, "invalid link text (\"%c\" may not appear in link text)", *src);
         }
         else if (*src == '<' || *src == '>')
             rb_raise(rb_eRangeError, "invalid link text (\"%c\" may not appear in link text)", *src);
-        else if (*src == ' ' && src == start && !trim)
+        else if (*src == ' ' && src == start && trim)
             start++;                            // we eat leading space
         else if (*src >= 0x20 && *src <= 0x7e)  // printable ASCII
         {
             start++;                            // we eat leading space
         else if (*src >= 0x20 && *src <= 0x7e)  // printable ASCII
         {
@@ -802,7 +802,7 @@ void _Wikitext_append_sanitized_link_target(parser_t *parser, str_t *output, boo
     }
 
     // trim trailing space if necessary
     }
 
     // trim trailing space if necessary
-    if (!trim && non_space > dest && output->ptr + output->len != non_space)
+    if (trim && non_space > dest && output->ptr + output->len != non_space)
         output->len -= (output->ptr + output->len) - non_space;
 }
 
         output->len -= (output->ptr + output->len) - non_space;
 }
 
@@ -813,7 +813,7 @@ VALUE Wikitext_parser_sanitize_link_target(VALUE self, VALUE string)
     GC_WRAP_STR(parser.link_target, link_target_gc);
     str_t *output = str_new();
     GC_WRAP_STR(output, output_gc);
     GC_WRAP_STR(parser.link_target, link_target_gc);
     str_t *output = str_new();
     GC_WRAP_STR(output, output_gc);
-    _Wikitext_append_sanitized_link_target(&parser, output, false);
+    _Wikitext_append_sanitized_link_target(&parser, output, true);
     return string_from_str(output);
 }
 
     return string_from_str(output);
 }
 
@@ -947,7 +947,7 @@ void _Wikitext_rollback_failed_internal_link(parser_t *parser)
     str_append(parser->output, link_start, sizeof(link_start) - 1);
     if (parser->link_target->len > 0)
     {
     str_append(parser->output, link_start, sizeof(link_start) - 1);
     if (parser->link_target->len > 0)
     {
-        _Wikitext_append_sanitized_link_target(parser, parser->output, true);
+        _Wikitext_append_sanitized_link_target(parser, parser->output, false);
         if (scope_includes_separator)
         {
             str_append(parser->output, separator, sizeof(separator) - 1);
         if (scope_includes_separator)
         {
             str_append(parser->output, separator, sizeof(separator) - 1);
@@ -2249,7 +2249,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
                     {
                         // use link target as link text
                         str_clear(parser->link_text);
                     {
                         // use link target as link text
                         str_clear(parser->link_text);
-                        _Wikitext_append_sanitized_link_target(parser, parser->link_text, false);
+                        _Wikitext_append_sanitized_link_target(parser, parser->link_text, true);
                     }
                     else
                         _Wikitext_trim_link_text(parser);
                     }
                     else
                         _Wikitext_trim_link_text(parser);