redcarpet 1.11.2 → 1.11.3

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.

data/ext/markdown.c CHANGED
@@ -145,6 +145,26 @@ is_safe_link(const char *link, size_t link_len)
145
145
  return 0;
146
146
  }
147
147
 
148
+ static void
149
+ unscape_text(struct buf *ob, struct buf *src)
150
+ {
151
+ size_t i = 0, org;
152
+ while (i < src->size) {
153
+ org = i;
154
+ while (i < src->size && src->data[i] != '\\')
155
+ i++;
156
+
157
+ if (i > org)
158
+ bufput(ob, src->data + org, i - org);
159
+
160
+ if (i + 1 >= src->size)
161
+ break;
162
+
163
+ bufputc(ob, src->data[i + 1]);
164
+ i += 2;
165
+ }
166
+ }
167
+
148
168
  /* cmp_link_ref • comparison function for link_ref sorted arrays */
149
169
  static int
150
170
  cmp_link_ref(void *key, void *array_entry)
@@ -253,14 +273,19 @@ tag_length(char *data, size_t size, enum mkd_autolink *autolink)
253
273
  }
254
274
 
255
275
  /* completing autolink test: no whitespace or ' or " */
256
- if (i >= size || i == '>')
276
+ if (i >= size)
257
277
  *autolink = MKDA_NOT_AUTOLINK;
278
+
258
279
  else if (*autolink) {
259
280
  j = i;
260
- while (i < size && data[i] != '>' && data[i] != '\''
261
- && data[i] != '"' && data[i] != ' ' && data[i] != '\t'
262
- && data[i] != '\t')
263
- i += 1;
281
+
282
+ while (i < size) {
283
+ if (data[i] == '\\') i += 2;
284
+ else if (data[i] == '>' || data[i] == '\'' ||
285
+ data[i] == '"' || isspace(data[i])) break;
286
+ else i += 1;
287
+ }
288
+
264
289
  if (i >= size) return 0;
265
290
  if (i > j && data[i] == '>') return i + 1;
266
291
  /* one of the forbidden chars has been found */
@@ -629,9 +654,12 @@ char_langle_tag(struct buf *ob, struct render *rndr, char *data, size_t offset,
629
654
 
630
655
  if (end > 2) {
631
656
  if (rndr->make.autolink && altype != MKDA_NOT_AUTOLINK) {
657
+ struct buf *u_link = rndr_newbuf(rndr);
632
658
  work.data = data + 1;
633
659
  work.size = end - 2;
634
- ret = rndr->make.autolink(ob, &work, altype, rndr->make.opaque);
660
+ unscape_text(u_link, &work);
661
+ ret = rndr->make.autolink(ob, u_link, altype, rndr->make.opaque);
662
+ rndr_popbuf(rndr);
635
663
  }
636
664
  else if (rndr->make.raw_html_tag)
637
665
  ret = rndr->make.raw_html_tag(ob, &work, rndr->make.opaque);
@@ -655,8 +683,13 @@ char_autolink(struct buf *ob, struct render *rndr, char *data, size_t offset, si
655
683
  while (work.size < size && !isspace(data[work.size]))
656
684
  work.size++;
657
685
 
658
- if (rndr->make.autolink)
659
- rndr->make.autolink(ob, &work, MKDA_NORMAL, rndr->make.opaque);
686
+ if (rndr->make.autolink) {
687
+ struct buf *u_link = rndr_newbuf(rndr);
688
+ unscape_text(u_link, &work);
689
+
690
+ rndr->make.autolink(ob, u_link, MKDA_NORMAL, rndr->make.opaque);
691
+ rndr_popbuf(rndr);
692
+ }
660
693
 
661
694
  return work.size;
662
695
  }
@@ -670,6 +703,7 @@ char_link(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t
670
703
  struct buf *content = 0;
671
704
  struct buf *link = 0;
672
705
  struct buf *title = 0;
706
+ struct buf *u_link = 0;
673
707
  size_t org_work_size = rndr->work.size;
674
708
  int text_has_nl = 0, ret = 0;
675
709
 
@@ -717,9 +751,11 @@ char_link(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t
717
751
  link_b = i;
718
752
 
719
753
  /* looking for link end: ' " ) */
720
- while (i < size && data[i] != '\'' && data[i] != '"' &&
721
- (data[i] != ')' || data[i - 1] == '\\'))
722
- i++;
754
+ while (i < size) {
755
+ if (data[i] == '\\') i += 2;
756
+ else if (data[i] == ')' || data[i] == '\'' || data[i] == '"') break;
757
+ else i += 1;
758
+ }
723
759
 
724
760
  if (i >= size) goto cleanup;
725
761
  link_e = i;
@@ -729,7 +765,12 @@ char_link(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t
729
765
  i++;
730
766
  title_b = i;
731
767
 
732
- while (i < size && (data[i] != ')' || data[i - 1] == '\\')) i++;
768
+ while (i < size) {
769
+ if (data[i] == '\\') i += 2;
770
+ else if (data[i] == ')') break;
771
+ else i += 1;
772
+ }
773
+
733
774
  if (i >= size) goto cleanup;
734
775
 
735
776
  /* skipping whitespaces after title */
@@ -854,14 +895,20 @@ char_link(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t
854
895
  else parse_inline(content, rndr, data + 1, txt_e - 1);
855
896
  }
856
897
 
898
+ if (link) {
899
+ u_link = rndr_newbuf(rndr);
900
+ unscape_text(u_link, link);
901
+ }
902
+
857
903
  /* calling the relevant rendering function */
858
904
  if (is_img) {
859
905
  if (ob->size && ob->data[ob->size - 1] == '!')
860
906
  ob->size -= 1;
861
907
 
862
- ret = rndr->make.image(ob, link, title, content, rndr->make.opaque);
863
- } else
864
- ret = rndr->make.link(ob, link, title, content, rndr->make.opaque);
908
+ ret = rndr->make.image(ob, u_link, title, content, rndr->make.opaque);
909
+ } else {
910
+ ret = rndr->make.link(ob, u_link, title, content, rndr->make.opaque);
911
+ }
865
912
 
866
913
  /* cleanup */
867
914
  cleanup:
data/ext/xhtml.c CHANGED
@@ -49,9 +49,41 @@ put_scaped_char(struct buf *ob, char c)
49
49
  }
50
50
  }
51
51
 
52
- /* lus_attr_escape • copy the buffer entity-escaping '<', '>', '&' and '"' */
53
52
  static void
54
- lus_attr_escape(struct buf *ob, const char *src, size_t size)
53
+ uri_escape(struct buf *ob, const char *src, size_t size)
54
+ {
55
+ size_t i;
56
+
57
+ for (i = 0; i < size; ++i) {
58
+ char c = src[i];
59
+
60
+ if (c == '%' && i + 2 < size && isxdigit(src[i + 1]) && isxdigit(src[i + 2])) {
61
+ bufput(ob, src + i, 3);
62
+ i += 2;
63
+ continue;
64
+ }
65
+
66
+ switch (c) {
67
+ case ';': case '/':
68
+ case '?': case ':':
69
+ case '@': case '=':
70
+ case '#': case '&':
71
+ case '.': case '+':
72
+ case '-':
73
+ bufputc(ob, c);
74
+ continue;
75
+ }
76
+
77
+ if (!isalnum(c))
78
+ bufprintf(ob, "%%%02x", (int)c);
79
+ else
80
+ bufputc(ob, c);
81
+ }
82
+ }
83
+
84
+ /* attr_escape • copy the buffer entity-escaping '<', '>', '&' and '"' */
85
+ static void
86
+ attr_escape(struct buf *ob, const char *src, size_t size)
55
87
  {
56
88
  size_t i = 0, org;
57
89
  while (i < size) {
@@ -122,7 +154,7 @@ rndr_autolink(struct buf *ob, struct buf *link, enum mkd_autolink type, void *op
122
154
  BUFPUTSL(ob, "<a href=\"");
123
155
  if (type == MKDA_EMAIL)
124
156
  BUFPUTSL(ob, "mailto:");
125
- bufput(ob, link->data, link->size);
157
+ uri_escape(ob, link->data, link->size);
126
158
  BUFPUTSL(ob, "\">");
127
159
 
128
160
  /*
@@ -131,9 +163,9 @@ rndr_autolink(struct buf *ob, struct buf *link, enum mkd_autolink type, void *op
131
163
  * want to print the `mailto:` prefix
132
164
  */
133
165
  if (bufprefix(link, "mailto:") == 0) {
134
- lus_attr_escape(ob, link->data + 7, link->size - 7);
166
+ attr_escape(ob, link->data + 7, link->size - 7);
135
167
  } else {
136
- lus_attr_escape(ob, link->data, link->size);
168
+ attr_escape(ob, link->data, link->size);
137
169
  }
138
170
 
139
171
  BUFPUTSL(ob, "</a>");
@@ -162,7 +194,7 @@ rndr_blockcode(struct buf *ob, struct buf *text, struct buf *lang, void *opaque)
162
194
  BUFPUTSL(ob, "<pre><code>");
163
195
 
164
196
  if (text)
165
- lus_attr_escape(ob, text->data, text->size);
197
+ attr_escape(ob, text->data, text->size);
166
198
 
167
199
  BUFPUTSL(ob, "</code></pre>\n");
168
200
  }
@@ -208,7 +240,7 @@ rndr_blockcode_github(struct buf *ob, struct buf *text, struct buf *lang, void *
208
240
  BUFPUTSL(ob, "<pre><code>");
209
241
 
210
242
  if (text)
211
- lus_attr_escape(ob, text->data, text->size);
243
+ attr_escape(ob, text->data, text->size);
212
244
 
213
245
  BUFPUTSL(ob, "</code></pre>\n");
214
246
  }
@@ -225,7 +257,7 @@ static int
225
257
  rndr_codespan(struct buf *ob, struct buf *text, void *opaque)
226
258
  {
227
259
  BUFPUTSL(ob, "<code>");
228
- if (text) lus_attr_escape(ob, text->data, text->size);
260
+ if (text) attr_escape(ob, text->data, text->size);
229
261
  BUFPUTSL(ob, "</code>");
230
262
  return 1;
231
263
  }
@@ -291,10 +323,10 @@ rndr_link(struct buf *ob, struct buf *link, struct buf *title, struct buf *conte
291
323
  return 0;
292
324
 
293
325
  BUFPUTSL(ob, "<a href=\"");
294
- if (link && link->size) lus_attr_escape(ob, link->data, link->size);
326
+ if (link && link->size) uri_escape(ob, link->data, link->size);
295
327
  if (title && title->size) {
296
328
  BUFPUTSL(ob, "\" title=\"");
297
- lus_attr_escape(ob, title->data, title->size); }
329
+ attr_escape(ob, title->data, title->size); }
298
330
  BUFPUTSL(ob, "\">");
299
331
  if (content && content->size) bufput(ob, content->data, content->size);
300
332
  BUFPUTSL(ob, "</a>");
@@ -406,13 +438,13 @@ rndr_image(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt,
406
438
  {
407
439
  if (!link || !link->size) return 0;
408
440
  BUFPUTSL(ob, "<img src=\"");
409
- lus_attr_escape(ob, link->data, link->size);
441
+ attr_escape(ob, link->data, link->size);
410
442
  BUFPUTSL(ob, "\" alt=\"");
411
443
  if (alt && alt->size)
412
- lus_attr_escape(ob, alt->data, alt->size);
444
+ attr_escape(ob, alt->data, alt->size);
413
445
  if (title && title->size) {
414
446
  BUFPUTSL(ob, "\" title=\"");
415
- lus_attr_escape(ob, title->data, title->size); }
447
+ attr_escape(ob, title->data, title->size); }
416
448
  BUFPUTSL(ob, "\" />");
417
449
  return 1;
418
450
  }
@@ -444,7 +476,7 @@ rndr_raw_html(struct buf *ob, struct buf *text, void *opaque)
444
476
 
445
477
 
446
478
  if (escape_html)
447
- lus_attr_escape(ob, text->data, text->size);
479
+ attr_escape(ob, text->data, text->size);
448
480
  else
449
481
  bufput(ob, text->data, text->size);
450
482
 
@@ -591,7 +623,7 @@ static void
591
623
  rndr_normal_text(struct buf *ob, struct buf *text, void *opaque)
592
624
  {
593
625
  if (text)
594
- lus_attr_escape(ob, text->data, text->size);
626
+ attr_escape(ob, text->data, text->size);
595
627
  }
596
628
 
597
629
  static void
data/lib/redcarpet.rb CHANGED
@@ -26,7 +26,7 @@
26
26
  # end
27
27
  #
28
28
  class Redcarpet
29
- VERSION = '1.11.2'
29
+ VERSION = '1.11.3'
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.11.2'
3
+ s.version = '1.11.3'
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-04-26'
6
+ s.date = '2011-04-27'
7
7
  s.email = 'vicent@github.com'
8
8
  s.homepage = 'http://github.com/tanoku/redcarpet'
9
9
  s.has_rdoc = true
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: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 11
9
- - 2
10
- version: 1.11.2
9
+ - 3
10
+ version: 1.11.3
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-04-26 00:00:00 +03:00
19
+ date: 2011-04-27 00:00:00 +03:00
20
20
  default_executable:
21
21
  dependencies: []
22
22