redcarpet 1.14.0 → 1.14.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of redcarpet might be problematic. Click here for more details.

@@ -172,7 +172,9 @@ is_safe_link(const char *link, size_t link_len)
172
172
  for (i = 0; i < valid_uris_count; ++i) {
173
173
  size_t len = strlen(valid_uris[i]);
174
174
 
175
- if (link_len > len && strncasecmp(link, valid_uris[i], len) == 0)
175
+ if (link_len > len &&
176
+ strncasecmp(link, valid_uris[i], len) == 0 &&
177
+ isalnum(link[len]))
176
178
  return 1;
177
179
  }
178
180
 
@@ -722,26 +724,12 @@ static size_t
722
724
  char_autolink(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t size)
723
725
  {
724
726
  struct buf work = { data, 0, 0, 0, 0 };
725
- char cclose = 0;
727
+ char copen = 0;
726
728
  size_t link_end;
727
729
 
728
- /* TODO:
729
- * what's the fastest check we can do, previous char
730
- * or URI prefix? We want to do the fastest one first
731
- * to break asap
732
- */
733
-
734
730
  if (offset > 0) {
735
- switch (data[-1]) {
736
- case '"': cclose = '"'; break;
737
- case '\'': cclose = '\''; break;
738
- case '(': cclose = ')'; break;
739
- case '[': cclose = ']'; break;
740
- case '{': cclose = '}'; break;
741
- case ' ': case '\t': case '\n': break;
742
- default:
731
+ if (!isspace(data[-1]) && !ispunct(data[-1]))
743
732
  return 0;
744
- }
745
733
  }
746
734
 
747
735
  if (!is_safe_link(data, size))
@@ -751,13 +739,60 @@ char_autolink(struct buf *ob, struct render *rndr, char *data, size_t offset, si
751
739
  while (link_end < size && !isspace(data[link_end]))
752
740
  link_end++;
753
741
 
754
- if (cclose != 0) {
755
- size_t i = link_end;
756
- while (i > 0 && data[i] != cclose)
757
- i--;
742
+ /* Skip punctuation at the end of the link */
743
+ if ((data[link_end - 1] == '.' ||
744
+ data[link_end - 1] == ',' ||
745
+ data[link_end - 1] == ';') &&
746
+ data[link_end - 2] != '\\')
747
+ link_end--;
748
+
749
+ /* See if the link finishes with a punctuation sign that can be closed. */
750
+ switch (data[link_end - 1]) {
751
+ case '"': copen = '"'; break;
752
+ case '\'': copen = '\''; break;
753
+ case ')': copen = '('; break;
754
+ case ']': copen = '['; break;
755
+ case '}': copen = '{'; break;
756
+ }
757
+
758
+ if (copen != 0) {
759
+ char *buf_start = data - offset;
760
+ char *buf_end = data + link_end - 2;
761
+
762
+ size_t open_delim = 1;
763
+
764
+ /* Try to close the final punctuation sign in this same line;
765
+ * if we managed to close it outside of the URL, that means that it's
766
+ * not part of the URL. If it closes inside the URL, that means it
767
+ * is part of the URL.
768
+ *
769
+ * Examples:
770
+ *
771
+ * foo http://www.pokemon.com/Pikachu_(Electric) bar
772
+ * => http://www.pokemon.com/Pikachu_(Electric)
773
+ *
774
+ * foo (http://www.pokemon.com/Pikachu_(Electric)) bar
775
+ * => http://www.pokemon.com/Pikachu_(Electric)
776
+ *
777
+ * foo http://www.pokemon.com/Pikachu_(Electric)) bar
778
+ * => http://www.pokemon.com/Pikachu_(Electric))
779
+ *
780
+ * (foo http://www.pokemon.com/Pikachu_(Electric)) bar
781
+ * => foo http://www.pokemon.com/Pikachu_(Electric)
782
+ */
783
+
784
+ while (buf_end >= buf_start && *buf_end != '\n' && open_delim) {
785
+ if (*buf_end == data[link_end - 1])
786
+ open_delim++;
787
+
788
+ if (*buf_end == copen)
789
+ open_delim--;
790
+
791
+ buf_end--;
792
+ }
758
793
 
759
- if (i > 0)
760
- link_end = i;
794
+ if (open_delim == 0)
795
+ link_end--;
761
796
  }
762
797
 
763
798
  work.size = link_end;
@@ -21,10 +21,10 @@
21
21
 
22
22
  #include "buffer.h"
23
23
 
24
- #define UPSKIRT_VERSION "1.14.0"
24
+ #define UPSKIRT_VERSION "1.14.1"
25
25
  #define UPSKIRT_VER_MAJOR 1
26
26
  #define UPSKIRT_VER_MINOR 14
27
- #define UPSKIRT_VER_REVISION 0
27
+ #define UPSKIRT_VER_REVISION 1
28
28
 
29
29
  /********************
30
30
  * TYPE DEFINITIONS *
data/lib/redcarpet.rb CHANGED
@@ -26,7 +26,7 @@
26
26
  # end
27
27
  #
28
28
  class Redcarpet
29
- VERSION = '1.14.0'
29
+ VERSION = '1.14.1'
30
30
 
31
31
  # Original Markdown formatted text.
32
32
  attr_reader :text
data/redcarpet.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'redcarpet'
3
- s.version = '1.14.0'
3
+ s.version = '1.14.1'
4
4
  s.summary = "Ruby bindings for libupskirt"
5
5
  s.description = 'A fast and safe Markdown to (X)HTML parser'
6
- s.date = '2011-05-17'
6
+ s.date = '2011-05-18'
7
7
  s.email = 'vicent@github.com'
8
8
  s.homepage = 'http://github.com/tanoku/redcarpet'
9
9
  s.authors = ["Natacha Porté", "Vicent Martí"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redcarpet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 47
4
+ hash: 45
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 14
9
- - 0
10
- version: 1.14.0
9
+ - 1
10
+ version: 1.14.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Natacha Port\xC3\xA9"
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-17 00:00:00 +03:00
19
+ date: 2011-05-18 00:00:00 +03:00
20
20
  default_executable:
21
21
  dependencies: []
22
22