commonmarker 0.23.5 → 0.23.7.pre1

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

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be9868bfb1c9bf09a7f274abf44ef7692be355141e7a4a3d956b3f889869cefd
4
- data.tar.gz: 8b09575b5209fcb2f80919dd46a89de97f52e61fc8f7b2d6d49c2243ff8c18ee
3
+ metadata.gz: f41f7e434edcc989547b4cc9d02007ae0eed60c393bd6f7ee8a288f139c6b537
4
+ data.tar.gz: 1c92f108fb98a076cf403c9e643f8a10b96d8c7ef359293686a27173e1e70436
5
5
  SHA512:
6
- metadata.gz: fffd100b88072cd573d8c3c13a81e437a08b69e48225b7abc2f8d20ffa188b021f1f779dab7d38b85c0d611261db7e4024a47ceeb7f08cba6334d8d5fc3f9e86
7
- data.tar.gz: ee8039d05a8cb7a31803a1da6f4f20ea77e7420a3549e1edcb11190e3f65edbff54ed88707d5576de02b7ae8d1195061e40b75c83ab34357964820bca8b30795
6
+ metadata.gz: ee9ef9c3ff7bcee7d054e1961ce402ddc067a082ea969752346b9642510473547f1fa8aea5e534b5113b7035ea8ddacdbb67c50e2490585bc3d1197d888ea4ac
7
+ data.tar.gz: 74b8df6b443d787cb9ce7110e7cabc34d5a0233a865b8cb67839b9bf1b11b636c02cd107a119e4fc02ca1122d3e736b84fc3fba0a674f5bd17928e25e3c4e8cf
@@ -269,6 +269,22 @@ static cmark_node *match(cmark_syntax_extension *ext, cmark_parser *parser,
269
269
  // inline was finished in inlines.c.
270
270
  }
271
271
 
272
+ static bool validate_protocol(char protocol[], uint8_t *data, int rewind) {
273
+ size_t len = strlen(protocol);
274
+
275
+ // Check that the protocol matches
276
+ for (int i = 1; i <= len; i++) {
277
+ if (data[-rewind - i] != protocol[len - i]) {
278
+ return false;
279
+ }
280
+ }
281
+
282
+ char prev_char = data[-rewind - len - 1];
283
+
284
+ // Make sure the character before the protocol is non-alphanumeric
285
+ return !cmark_isalnum(prev_char);
286
+ }
287
+
272
288
  static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset, int depth) {
273
289
  // postprocess_text can recurse very deeply if there is a very long line of
274
290
  // '@' only. Stop at a reasonable depth to ensure it cannot crash.
@@ -278,6 +294,8 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
278
294
  uint8_t *data = text->as.literal.data,
279
295
  *at;
280
296
  size_t size = text->as.literal.len;
297
+ bool auto_mailto = true;
298
+ bool is_xmpp = false;
281
299
  int rewind, max_rewind,
282
300
  nb = 0, np = 0, ns = 0;
283
301
 
@@ -304,8 +322,18 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
304
322
  if (strchr(".+-_", c) != NULL)
305
323
  continue;
306
324
 
307
- if (c == '/')
308
- ns++;
325
+ if (strchr(":", c) != NULL) {
326
+ if (validate_protocol("mailto:", data, rewind)) {
327
+ auto_mailto = false;
328
+ continue;
329
+ }
330
+
331
+ if (validate_protocol("xmpp:", data, rewind)) {
332
+ auto_mailto = false;
333
+ is_xmpp = true;
334
+ continue;
335
+ }
336
+ }
309
337
 
310
338
  break;
311
339
  }
@@ -325,6 +353,8 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
325
353
  nb++;
326
354
  else if (c == '.' && link_end < size - 1 && cmark_isalnum(data[link_end + 1]))
327
355
  np++;
356
+ else if (c == '/' && is_xmpp)
357
+ continue;
328
358
  else if (c != '-' && c != '_')
329
359
  break;
330
360
  }
@@ -347,7 +377,8 @@ static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset,
347
377
  cmark_node *link_node = cmark_node_new_with_mem(CMARK_NODE_LINK, parser->mem);
348
378
  cmark_strbuf buf;
349
379
  cmark_strbuf_init(parser->mem, &buf, 10);
350
- cmark_strbuf_puts(&buf, "mailto:");
380
+ if (auto_mailto)
381
+ cmark_strbuf_puts(&buf, "mailto:");
351
382
  cmark_strbuf_put(&buf, data - rewind, (bufsize_t)(link_end + rewind));
352
383
  link_node->as.link.url = cmark_chunk_buf_detach(&buf);
353
384
 
@@ -1,7 +1,7 @@
1
1
  #ifndef CMARK_GFM_VERSION_H
2
2
  #define CMARK_GFM_VERSION_H
3
3
 
4
- #define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) | 4)
5
- #define CMARK_GFM_VERSION_STRING "0.29.0.gfm.4"
4
+ #define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) | 6)
5
+ #define CMARK_GFM_VERSION_STRING "0.29.0.gfm.6"
6
6
 
7
7
  #endif
@@ -41,6 +41,8 @@ typedef struct bracket {
41
41
  bool image;
42
42
  bool active;
43
43
  bool bracket_after;
44
+ bool in_bracket_image0;
45
+ bool in_bracket_image1;
44
46
  } bracket;
45
47
 
46
48
  typedef struct subject{
@@ -516,6 +518,8 @@ static void push_bracket(subject *subj, bool image, cmark_node *inl_text) {
516
518
  bracket *b = (bracket *)subj->mem->calloc(1, sizeof(bracket));
517
519
  if (subj->last_bracket != NULL) {
518
520
  subj->last_bracket->bracket_after = true;
521
+ b->in_bracket_image0 = subj->last_bracket->in_bracket_image0;
522
+ b->in_bracket_image1 = subj->last_bracket->in_bracket_image1;
519
523
  }
520
524
  b->image = image;
521
525
  b->active = true;
@@ -524,6 +528,11 @@ static void push_bracket(subject *subj, bool image, cmark_node *inl_text) {
524
528
  b->previous_delimiter = subj->last_delim;
525
529
  b->position = subj->pos;
526
530
  b->bracket_after = false;
531
+ if (image) {
532
+ b->in_bracket_image1 = true;
533
+ } else {
534
+ b->in_bracket_image0 = true;
535
+ }
527
536
  subj->last_bracket = b;
528
537
  }
529
538
 
@@ -1254,6 +1263,17 @@ match:
1254
1263
  }
1255
1264
  opener = opener->previous;
1256
1265
  }
1266
+ bool in_bracket_image1 = false;
1267
+ if (opener) {
1268
+ in_bracket_image1 = opener->in_bracket_image1;
1269
+ }
1270
+ bracket *opener2 = subj->last_bracket;
1271
+ while (opener2 != opener) {
1272
+ if (opener2->image) {
1273
+ opener2->in_bracket_image1 = in_bracket_image1;
1274
+ }
1275
+ opener2 = opener2->previous;
1276
+ }
1257
1277
  }
1258
1278
 
1259
1279
  return NULL;
@@ -1662,10 +1682,15 @@ cmark_chunk *cmark_inline_parser_get_chunk(cmark_inline_parser *parser) {
1662
1682
  }
1663
1683
 
1664
1684
  int cmark_inline_parser_in_bracket(cmark_inline_parser *parser, int image) {
1665
- for (bracket *b = parser->last_bracket; b; b = b->previous)
1666
- if (b->active && b->image == (image != 0))
1667
- return 1;
1668
- return 0;
1685
+ bracket *b = parser->last_bracket;
1686
+ if (!b) {
1687
+ return 0;
1688
+ }
1689
+ if (image != 0) {
1690
+ return b->in_bracket_image1;
1691
+ } else {
1692
+ return b->in_bracket_image0;
1693
+ }
1669
1694
  }
1670
1695
 
1671
1696
  void cmark_node_unput(cmark_node *node, int n) {
@@ -33,20 +33,22 @@ module CommonMarker
33
33
  format: [:html, :xml, :commonmark, :plaintext].freeze,
34
34
  }.freeze
35
35
 
36
- def self.process_options(option, type)
37
- case option
38
- when Symbol
39
- OPTS.fetch(type).fetch(option)
40
- when Array
41
- raise TypeError if option.none?
36
+ class << self
37
+ def process_options(option, type)
38
+ case option
39
+ when Symbol
40
+ OPTS.fetch(type).fetch(option)
41
+ when Array
42
+ raise TypeError if option.none?
42
43
 
43
- # neckbearding around. the map will both check the opts and then bitwise-OR it
44
- OPTS.fetch(type).fetch_values(*option).inject(0, :|)
45
- else
46
- raise TypeError, "option type must be a valid symbol or array of symbols within the #{name}::OPTS[:#{type}] context"
44
+ # neckbearding around. the map will both check the opts and then bitwise-OR it
45
+ OPTS.fetch(type).fetch_values(*option).inject(0, :|)
46
+ else
47
+ raise TypeError, "option type must be a valid symbol or array of symbols within the #{name}::OPTS[:#{type}] context"
48
+ end
49
+ rescue KeyError => e
50
+ raise TypeError, "option ':#{e.key}' does not exist for #{name}::OPTS[:#{type}]"
47
51
  end
48
- rescue KeyError => e
49
- raise TypeError, "option ':#{e.key}' does not exist for #{name}::OPTS[:#{type}]"
50
- end
52
+ end
51
53
  end
52
54
  end
@@ -113,7 +113,7 @@ module CommonMarker
113
113
  )
114
114
  (?=\s|>|/>)
115
115
  }xi,
116
- '&lt;\1'
116
+ '&lt;\1',
117
117
  )
118
118
  else
119
119
  str
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CommonMarker
4
- VERSION = "0.23.5"
4
+ VERSION = "0.23.7.pre1"
5
5
  end
data/lib/commonmarker.rb CHANGED
@@ -12,32 +12,34 @@ begin
12
12
  require "awesome_print"
13
13
  rescue LoadError; end # rubocop:disable Lint/SuppressedException
14
14
  module CommonMarker
15
- # Public: Parses a Markdown string into an HTML string.
16
- #
17
- # text - A {String} of text
18
- # option - Either a {Symbol} or {Array of Symbol}s indicating the render options
19
- # extensions - An {Array of Symbol}s indicating the extensions to use
20
- #
21
- # Returns a {String} of converted HTML.
22
- def self.render_html(text, options = :DEFAULT, extensions = [])
23
- raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
15
+ class << self
16
+ # Public: Parses a Markdown string into an HTML string.
17
+ #
18
+ # text - A {String} of text
19
+ # option - Either a {Symbol} or {Array of Symbol}s indicating the render options
20
+ # extensions - An {Array of Symbol}s indicating the extensions to use
21
+ #
22
+ # Returns a {String} of converted HTML.
23
+ def render_html(text, options = :DEFAULT, extensions = [])
24
+ raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
24
25
 
25
- opts = Config.process_options(options, :render)
26
- Node.markdown_to_html(text.encode("UTF-8"), opts, extensions)
27
- end
26
+ opts = Config.process_options(options, :render)
27
+ Node.markdown_to_html(text.encode("UTF-8"), opts, extensions)
28
+ end
28
29
 
29
- # Public: Parses a Markdown string into a `document` node.
30
- #
31
- # string - {String} to be parsed
32
- # option - A {Symbol} or {Array of Symbol}s indicating the parse options
33
- # extensions - An {Array of Symbol}s indicating the extensions to use
34
- #
35
- # Returns the `document` node.
36
- def self.render_doc(text, options = :DEFAULT, extensions = [])
37
- raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
30
+ # Public: Parses a Markdown string into a `document` node.
31
+ #
32
+ # string - {String} to be parsed
33
+ # option - A {Symbol} or {Array of Symbol}s indicating the parse options
34
+ # extensions - An {Array of Symbol}s indicating the extensions to use
35
+ #
36
+ # Returns the `document` node.
37
+ def render_doc(text, options = :DEFAULT, extensions = [])
38
+ raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
38
39
 
39
- opts = Config.process_options(options, :parse)
40
- text = text.encode("UTF-8")
41
- Node.parse_document(text, text.bytesize, opts, extensions)
42
- end
40
+ opts = Config.process_options(options, :parse)
41
+ text = text.encode("UTF-8")
42
+ Node.parse_document(text, text.bytesize, opts, extensions)
43
+ end
44
+ end
43
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commonmarker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.5
4
+ version: 0.23.7.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-05-31 00:00:00.000000000 Z
12
+ date: 2022-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print
@@ -251,11 +251,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
251
251
  version: '4.0'
252
252
  required_rubygems_version: !ruby/object:Gem::Requirement
253
253
  requirements:
254
- - - ">="
254
+ - - ">"
255
255
  - !ruby/object:Gem::Version
256
- version: '0'
256
+ version: 1.3.1
257
257
  requirements: []
258
- rubygems_version: 3.3.13
258
+ rubygems_version: 3.3.7
259
259
  signing_key:
260
260
  specification_version: 4
261
261
  summary: CommonMark parser and renderer. Written in C, wrapped in Ruby.