commonmarker 0.21.2 → 0.22.0

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: ac3365deb1dd8288503331626fc20ec583a5f96a23e25d330f4ff47e526bfc54
4
- data.tar.gz: 975bcb958eb2e994a15090311088ff95870af95b1fc2d73bc1c4eb216fe69388
3
+ metadata.gz: f5356237deaf85df9914e0c7fa3f121fa0301579653b83b006df4dd8404c65f2
4
+ data.tar.gz: 9d4a09830e1c107dec28e47a3c0ab96f2cc6bcd9786982e38607752022ec12f1
5
5
  SHA512:
6
- metadata.gz: 531cda0280a75a40c139969287106646c8b2cef181b48249055f3a896bc4329485a0f70ac59f6f3a85eed00247c15f4a6785f478b957ebd3594be3074a9d25a9
7
- data.tar.gz: 3bb88a326ea1e0e7f99da2b459b90cac2ea748e57d933029c11278f230064a433a00889c93d65851dfef4b131ba46562a33d4597ef677f3e382325a712b0ffe6
6
+ metadata.gz: 7e43f365eb266fa8c0627572999a2102df7dd65e0404917c5fa6054b532c526a35ad5d0ef9423cf68033edc52fb0c20da79ca73d7345b04d4493f33bff35ed73
7
+ data.tar.gz: 0e5da729c2247288a1bf60672f572f785def6e2a1726afeaf87aa1332d083e4834d52c403479a36437f9c0a9e99548569f7d5bc092a405304ccef81ac71096b1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # CommonMarker
2
2
 
3
- [![Build Status](https://travis-ci.org/gjtorikian/commonmarker.svg)](https://travis-ci.org/gjtorikian/commonmarker) [![Gem Version](https://badge.fury.io/rb/commonmarker.svg)](http://badge.fury.io/rb/commonmarker)
3
+ ![Build Status](https://github.com/gjtorikian/commonmarker/workflows/CI/badge.svg) [![Gem Version](https://badge.fury.io/rb/commonmarker.svg)](http://badge.fury.io/rb/commonmarker)
4
4
 
5
5
  Ruby wrapper for [libcmark-gfm](https://github.com/github/cmark),
6
6
  GitHub's fork of the reference parser for CommonMark. It passes all of the C tests, and is therefore spec-complete. It also includes extensions to the CommonMark spec as documented in the [GitHub Flavored Markdown spec](http://github.github.com/gfm/), such as support for tables, strikethroughs, and autolinking.
data/bin/commonmarker CHANGED
@@ -13,8 +13,8 @@ $LOAD_PATH.unshift File.expand_path('lib', root)
13
13
  def parse_options
14
14
  options = OpenStruct.new
15
15
  extensions = CommonMarker.extensions
16
- parse_options = CommonMarker::Config::Parse
17
- render_options = CommonMarker::Config::Render
16
+ parse_options = CommonMarker::Config::OPTS.fetch(:parse)
17
+ render_options = CommonMarker::Config::OPTS.fetch(:render)
18
18
 
19
19
  options.active_extensions = []
20
20
  options.active_parse_options = [:DEFAULT]
data/commonmarker.gemspec CHANGED
@@ -21,12 +21,10 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.executables = ['commonmarker']
23
23
  s.require_paths = %w[lib ext]
24
- s.required_ruby_version = ['>= 2.4.10', '< 4.0']
24
+ s.required_ruby_version = ['>= 2.6', '< 4.0']
25
25
 
26
26
  s.rdoc_options += ['-x', 'ext/commonmarker/cmark/.*']
27
27
 
28
- s.add_dependency 'ruby-enum', '~> 0.5'
29
-
30
28
  s.add_development_dependency 'awesome_print'
31
29
  s.add_development_dependency 'json', '~> 2.3'
32
30
  s.add_development_dependency 'minitest', '~> 5.6'
@@ -45,6 +45,13 @@ static VALUE encode_utf8_string(const char *c_string) {
45
45
  return string;
46
46
  }
47
47
 
48
+ /* Encode a C string using the encoding from Ruby string +source+. */
49
+ static VALUE encode_source_string(const char *c_string, VALUE source) {
50
+ VALUE string = rb_str_new2(c_string);
51
+ rb_enc_copy(string, source);
52
+ return string;
53
+ }
54
+
48
55
  static void rb_mark_c_struct(void *data) {
49
56
  cmark_node *node = data;
50
57
  cmark_node *child;
@@ -1130,7 +1137,8 @@ static VALUE rb_html_escape_href(VALUE self, VALUE rb_text) {
1130
1137
  if (houdini_escape_href(&buf, (const uint8_t *)RSTRING_PTR(rb_text),
1131
1138
  RSTRING_LEN(rb_text))) {
1132
1139
  result = (char *)cmark_strbuf_detach(&buf);
1133
- return rb_str_new2(result);
1140
+ return encode_source_string(result, rb_text);
1141
+
1134
1142
  }
1135
1143
 
1136
1144
  return rb_text;
@@ -1150,7 +1158,7 @@ static VALUE rb_html_escape_html(VALUE self, VALUE rb_text) {
1150
1158
  if (houdini_escape_html0(&buf, (const uint8_t *)RSTRING_PTR(rb_text),
1151
1159
  RSTRING_LEN(rb_text), 0)) {
1152
1160
  result = (char *)cmark_strbuf_detach(&buf);
1153
- return rb_str_new2(result);
1161
+ return encode_source_string(result, rb_text);
1154
1162
  }
1155
1163
 
1156
1164
  return rb_text;
@@ -1,55 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ruby-enum'
4
3
  module CommonMarker
5
4
  # For Ruby::Enum, these must be classes, not modules
6
5
  module Config
7
- class Parse
8
- include Ruby::Enum
9
-
10
- define :DEFAULT, 0
11
- define :VALIDATE_UTF8, (1 << 9)
12
- define :SMART, (1 << 10)
13
- define :LIBERAL_HTML_TAG, (1 << 12)
14
- define :FOOTNOTES, (1 << 13)
15
- define :STRIKETHROUGH_DOUBLE_TILDE, (1 << 14)
16
- define :UNSAFE, (1 << 17)
17
- end
18
-
19
- class Render
20
- include Ruby::Enum
21
-
22
- define :DEFAULT, 0
23
- define :SOURCEPOS, (1 << 1)
24
- define :HARDBREAKS, (1 << 2)
25
- define :NOBREAKS, (1 << 4)
26
- define :GITHUB_PRE_LANG, (1 << 11)
27
- define :TABLE_PREFER_STYLE_ATTRIBUTES, (1 << 15)
28
- define :FULL_INFO_STRING, (1 << 16)
29
- define :UNSAFE, (1 << 17)
30
- define :FOOTNOTES, (1 << 13)
31
- end
6
+ # See https://github.com/github/cmark-gfm/blob/master/src/cmark-gfm.h#L673
7
+ OPTS = {
8
+ parse: {
9
+ DEFAULT: 0,
10
+ VALIDATE_UTF8: (1 << 9),
11
+ SMART: (1 << 10),
12
+ LIBERAL_HTML_TAG: (1 << 12),
13
+ FOOTNOTES: (1 << 13),
14
+ STRIKETHROUGH_DOUBLE_TILDE: (1 << 14),
15
+ UNSAFE: (1 << 17)
16
+ }.freeze,
17
+ render: {
18
+ DEFAULT: 0,
19
+ SOURCEPOS: (1 << 1),
20
+ HARDBREAKS: (1 << 2),
21
+ NOBREAKS: (1 << 4),
22
+ GITHUB_PRE_LANG: (1 << 11),
23
+ TABLE_PREFER_STYLE_ATTRIBUTES: (1 << 15),
24
+ FULL_INFO_STRING: (1 << 16),
25
+ UNSAFE: (1 << 17),
26
+ FOOTNOTES: (1 << 13)
27
+ }.freeze
28
+ }.freeze
32
29
 
33
30
  def self.process_options(option, type)
34
- type = Config.const_get(type.capitalize)
35
31
  case option
36
32
  when Symbol
37
- check_option(option, type)
38
- type.to_h[option]
33
+ OPTS.fetch(type).fetch(option)
39
34
  when Array
40
- option = [nil] if option.empty?
35
+ raise TypeError if option.none?
36
+
41
37
  # neckbearding around. the map will both check the opts and then bitwise-OR it
42
- option.map do |o|
43
- check_option(o, type)
44
- type.to_h[o]
45
- end.inject(0, :|)
38
+ OPTS.fetch(type).fetch_values(*option).inject(0, :|)
46
39
  else
47
- raise TypeError, "option type must be a valid symbol or array of symbols within the #{type} context"
40
+ raise TypeError, "option type must be a valid symbol or array of symbols within the #{name}::OPTS[:#{type}] context"
48
41
  end
49
- end
50
-
51
- def self.check_option(option, type)
52
- raise TypeError, "option ':#{option}' does not exist for #{type}" unless type.key?(option)
42
+ rescue KeyError => e
43
+ raise TypeError, "option ':#{e.key}' does not exist for #{name}::OPTS[:#{type}]"
53
44
  end
54
45
  end
55
46
  end
@@ -27,11 +27,9 @@ module CommonMarker
27
27
  list_tight
28
28
  fence_info
29
29
  ].map do |name|
30
- begin
31
- [name, __send__(name)]
32
- rescue NodeError
33
- nil
34
- end
30
+ [name, __send__(name)]
31
+ rescue NodeError
32
+ nil
35
33
  end.compact
36
34
 
37
35
  printer.seplist(attrs) do |name, value|
@@ -129,7 +129,7 @@ module CommonMarker
129
129
  end
130
130
 
131
131
  def option_enabled?(opt)
132
- (@opts & CommonMarker::Config::Render.value(opt)) != 0
132
+ (@opts & CommonMarker::Config::OPTS.dig(:render, opt)) != 0
133
133
  end
134
134
  end
135
135
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CommonMarker
4
- VERSION = '0.21.2'
4
+ VERSION = '0.22.0'
5
5
  end
@@ -70,7 +70,7 @@ module CommonMarker
70
70
  err = assert_raises TypeError do
71
71
  CommonMarker.render_html("foo \n baz", [:SMART])
72
72
  end
73
- assert_equal('option \':SMART\' does not exist for CommonMarker::Config::Render', err.message)
73
+ assert_equal('option \':SMART\' does not exist for CommonMarker::Config::OPTS[:render]', err.message)
74
74
 
75
75
  assert_raises TypeError do
76
76
  CommonMarker.render_doc("foo \n baz", 123)
@@ -79,7 +79,7 @@ module CommonMarker
79
79
  err = assert_raises TypeError do
80
80
  CommonMarker.render_doc("foo \n baz", :safe)
81
81
  end
82
- assert_equal('option \':safe\' does not exist for CommonMarker::Config::Parse', err.message)
82
+ assert_equal('option \':safe\' does not exist for CommonMarker::Config::OPTS[:parse]', err.message)
83
83
 
84
84
  assert_raises TypeError do
85
85
  CommonMarker.render_doc("foo \n baz", :totes_fake)
@@ -27,4 +27,21 @@ class TestRenderer < Minitest::Test
27
27
  results = CommonMarker::HtmlRenderer.new.render(doc)
28
28
  assert_equal 2, results.scan(/<tbody>/).size
29
29
  end
30
+
31
+ def test_escape_html_encoding
32
+ my_renderer = Class.new(HtmlRenderer) do
33
+ attr_reader :input_encoding, :output_encoding
34
+
35
+ def text(node)
36
+ @input_encoding = node.string_content.encoding
37
+ escape_html(node.string_content).tap do |escaped|
38
+ @output_encoding = escaped.encoding
39
+ end
40
+ end
41
+ end
42
+
43
+ renderer = my_renderer.new
44
+ assert_equal Encoding::UTF_8, renderer.render(@doc).encoding
45
+ assert_equal renderer.input_encoding, renderer.output_encoding
46
+ end
30
47
  end
metadata CHANGED
@@ -1,30 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commonmarker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.2
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  - Ashe Connor
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-11 00:00:00.000000000 Z
12
+ date: 2021-06-20 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: ruby-enum
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '0.5'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '0.5'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: awesome_print
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -153,7 +139,7 @@ dependencies:
153
139
  version: '0'
154
140
  description: A fast, safe, extensible parser for CommonMark. This wraps the official
155
141
  libcmark library.
156
- email:
142
+ email:
157
143
  executables:
158
144
  - commonmarker
159
145
  extensions:
@@ -272,7 +258,7 @@ homepage: https://github.com/gjtorikian/commonmarker
272
258
  licenses:
273
259
  - MIT
274
260
  metadata: {}
275
- post_install_message:
261
+ post_install_message:
276
262
  rdoc_options:
277
263
  - "-x"
278
264
  - ext/commonmarker/cmark/.*
@@ -283,7 +269,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
283
269
  requirements:
284
270
  - - ">="
285
271
  - !ruby/object:Gem::Version
286
- version: 2.4.10
272
+ version: '2.6'
287
273
  - - "<"
288
274
  - !ruby/object:Gem::Version
289
275
  version: '4.0'
@@ -294,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
294
280
  version: '0'
295
281
  requirements: []
296
282
  rubygems_version: 3.1.4
297
- signing_key:
283
+ signing_key:
298
284
  specification_version: 4
299
285
  summary: CommonMark parser and renderer. Written in C, wrapped in Ruby.
300
286
  test_files: