berns 3.1.4 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bce7bd3384f01f587a75bd722cca156b4357e0953bd90a5a2c8f97a630deb8db
4
- data.tar.gz: 2c830eb788274a6d96e3e0a7db0e75826dea451eabecb3444878901d6e1adb08
3
+ metadata.gz: e477eaf0fc69e3218e9bd93d0ece7a2635b42157dfa4dac49f44134822f5347e
4
+ data.tar.gz: d536572a3ecfb3fb84eac0a5624fb2fb662079de615c0afd431dffe940c064f1
5
5
  SHA512:
6
- metadata.gz: d20138c2bc54ab035eb9d79f1e0ae18065ba422157fa453258acd5d974f08062afee105b50d2d3564b3e4882b4331ec6f93e4da3a3091a1440ad8a74c10f1686
7
- data.tar.gz: 598843f7a87302d0a59ba53d8e52caf0f864a2e146b473c2d95b50f1da5b11536603f4d9f51f990de385bbaa08fb6e273381672eb823ddda2b0bb614532aef33
6
+ metadata.gz: 43620249a6d836dca7da50946bf63835b5d21cadcd2fc0de543be5adb11ac4d0f97ee086f139cb49ed600d09b93ba262414f2f7d9113cabd6b50a85a597ea619
7
+ data.tar.gz: 6354871cfe7c0e1558de95f0c5230d3e9edeeed778868496192da8583b747411d08bd16826faa2d53c67e65f0c6216c1c48a751e4abb17d74623351c6c33ead4
data/LICENSE.txt CHANGED
@@ -1,21 +1,20 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 Taylor Beck
3
+ Copyright © 2021 Taylor Beck and Evan Lecklider
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the Software), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
11
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
14
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.org CHANGED
@@ -91,6 +91,10 @@ The =sanitize= method strips HTML tags from strings.
91
91
  Berns.sanitize('This <span>should be clean</span>') # => 'This should be clean'
92
92
  #+end_src
93
93
 
94
+ Note that this is an extremely naive implementation of HTML sanitization that
95
+ literally just looks for "<" and ">" characters and removes the contents between
96
+ them. This should probably only be used on trusted strings.
97
+
94
98
  *** Standard and void elements
95
99
 
96
100
  All standard and void HTML elements are defined as methods on Berns, so you can
data/ext/berns/berns.c CHANGED
@@ -1,5 +1,4 @@
1
1
  #include "ruby.h"
2
- #include "extconf.h"
3
2
  #include "hescape.h"
4
3
 
5
4
  static const char *attr_close = "\"";
@@ -47,10 +46,10 @@ static const size_t sllen = 1;
47
46
  * Macro to define a "dynamic" function that generates a void element.
48
47
  */
49
48
  #define VOID_ELEMENT(element_name) \
50
- static VALUE external_##element_name##_element(int argc, VALUE* argv, RB_UNUSED_VAR(VALUE self)) { \
49
+ static VALUE external_##element_name##_element(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self)) { \
51
50
  rb_check_arity(argc, 0, 1); \
52
51
  \
53
- char *tag = #element_name; \
52
+ const char *tag = #element_name; \
54
53
  char *string = void_element(tag, strlen(tag), argv[0]); \
55
54
  VALUE rstring = rb_utf8_str_new_cstr(string); \
56
55
  free(string); \
@@ -62,11 +61,11 @@ static const size_t sllen = 1;
62
61
  * Macro to define a "dynamic" function that generates a standard element.
63
62
  */
64
63
  #define STANDARD_ELEMENT(element_name) \
65
- static VALUE external_##element_name##_element(int argc, VALUE* argv, RB_UNUSED_VAR(VALUE self)) { \
64
+ static VALUE external_##element_name##_element(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self)) { \
66
65
  rb_check_arity(argc, 0, 1); \
67
66
  \
68
67
  CONTENT_FROM_BLOCK; \
69
- char *tag = #element_name; \
68
+ const char *tag = #element_name; \
70
69
  char *string = element(tag, strlen(tag), RSTRING_PTR(content), RSTRING_LEN(content), argv[0]); \
71
70
  VALUE rstring = rb_utf8_str_new_cstr(string); \
72
71
  free(string); \
@@ -78,25 +77,81 @@ static const size_t sllen = 1;
78
77
  /*
79
78
  * "Safe strcpy" - https://twitter.com/hyc_symas/status/1102573036534972416?s=12
80
79
  */
81
- static char *stecpy(char *destination, const char *source, const char *end) {
80
+ static char * stecpy(char *destination, const char *source, const char *end) {
81
+ if (end) {
82
+ end--;
83
+ }
84
+
82
85
  while (*source && destination < end) {
83
86
  *destination++ = *source++;
84
87
  }
85
88
 
86
- if (destination < end) {
89
+ if (destination) {
87
90
  *destination = '\0';
88
91
  }
89
92
 
90
93
  return destination;
91
94
  }
92
95
 
96
+ /*
97
+ * The external API for Berns.sanitize
98
+ *
99
+ * string should be a string or nil, anything else will raise an error.
100
+ *
101
+ */
102
+ static VALUE external_sanitize(RB_UNUSED_VAR(VALUE self), VALUE string) {
103
+ if (TYPE(string) == T_NIL) {
104
+ return Qnil;
105
+ }
106
+
107
+ StringValue(string);
108
+
109
+ size_t slen = RSTRING_LEN(string);
110
+ char *str = RSTRING_PTR(string);
111
+
112
+ char dest[slen + 1];
113
+
114
+ unsigned int index = 0;
115
+ unsigned int open = 0;
116
+ unsigned int modified = 0;
117
+ unsigned int entity = 0;
118
+
119
+ for (unsigned int i = 0; i < slen; i++) {
120
+ if (str[i] == '<') {
121
+ open = 1;
122
+ modified = 1;
123
+ } else if (str[i] == '>') {
124
+ open = 0;
125
+ } else if (str[i] == '&') {
126
+ entity = 1;
127
+ modified = 1;
128
+ } else if (str[i] == ';') {
129
+ entity = 0;
130
+ } else if (!open && !entity) {
131
+ dest[index++] = str[i];
132
+ }
133
+ }
134
+
135
+ dest[index] = '\0';
136
+
137
+ /*
138
+ * If the string was never modified, return the original string, otherwise
139
+ * create a new string from our destination buffer.
140
+ */
141
+ if (modified) {
142
+ return rb_utf8_str_new_cstr(dest);
143
+ } else {
144
+ return string;
145
+ }
146
+ }
147
+
93
148
  /*
94
149
  * The external API for Berns.escape_html.
95
150
  *
96
151
  * string should be a string, anything else will raise an error.
97
152
  *
98
153
  */
99
- static VALUE external_escape_html(const VALUE self, VALUE string) {
154
+ static VALUE external_escape_html(RB_UNUSED_VAR(VALUE self), VALUE string) {
100
155
  StringValue(string);
101
156
 
102
157
  uint8_t *dest = NULL;
@@ -123,7 +178,6 @@ static VALUE external_escape_html(const VALUE self, VALUE string) {
123
178
  static char * empty_value_to_attribute(const char *attr, const size_t attrlen) {
124
179
  size_t total_size = attrlen + 1;
125
180
  char *dest = malloc(total_size);
126
- char *ptr = NULL;
127
181
  char *end = dest + total_size;
128
182
 
129
183
  stecpy(dest, attr, end);
@@ -140,7 +194,6 @@ static char * string_value_to_attribute(const char *attr, const size_t attrlen,
140
194
  if (vallen == 0) {
141
195
  size_t total_size = attrlen + 1;
142
196
  char *dest = malloc(total_size);
143
- char *ptr = NULL;
144
197
  char *end = dest + total_size;
145
198
 
146
199
  stecpy(dest, attr, end);
@@ -168,7 +221,7 @@ static char * string_value_to_attribute(const char *attr, const size_t attrlen,
168
221
  }
169
222
  }
170
223
 
171
- static char * hash_value_to_attribute(char *attr, const size_t attrlen, VALUE value) {
224
+ static char * hash_value_to_attribute(const char *attr, const size_t attrlen, VALUE value) {
172
225
  if (TYPE(value) == T_IMEMO) {
173
226
  return strdup("");
174
227
  }
@@ -224,17 +277,17 @@ static char * hash_value_to_attribute(char *attr, const size_t attrlen, VALUE va
224
277
 
225
278
  char subattr[subattr_len + 1];
226
279
  char *ptr = subattr;
227
- char *end = subattr + sizeof(subattr);
280
+ char *subend = subattr + subattr_len + 1;
228
281
 
229
282
  if (attrlen > 0) {
230
- ptr = stecpy(ptr, attr, end);
283
+ ptr = stecpy(ptr, attr, subend);
231
284
  }
232
285
 
233
286
  if (attrlen > 0 && subkey_len > 0) {
234
- ptr = stecpy(ptr, dash, end);
287
+ ptr = stecpy(ptr, dash, subend);
235
288
  }
236
289
 
237
- stecpy(ptr, RSTRING_PTR(subkey), end);
290
+ stecpy(ptr, RSTRING_PTR(subkey), subend);
238
291
 
239
292
  char *combined;
240
293
 
@@ -246,7 +299,7 @@ static char * hash_value_to_attribute(char *attr, const size_t attrlen, VALUE va
246
299
  case T_NIL:
247
300
  /* Fall through. */
248
301
  case T_TRUE:
249
- combined = string_value_to_attribute(subattr, subattr_len, "", 0);
302
+ combined = empty_value_to_attribute(subattr, subattr_len);
250
303
  break;
251
304
 
252
305
  case T_STRING:
@@ -326,6 +379,7 @@ static char * to_attribute(VALUE attr, VALUE value) {
326
379
 
327
380
  switch(TYPE(value)) {
328
381
  case T_NIL:
382
+ /* Fall through. */
329
383
  case T_TRUE:
330
384
  val = empty_value_to_attribute(RSTRING_PTR(attr), RSTRING_LEN(attr));
331
385
  break;
@@ -389,7 +443,7 @@ static VALUE external_to_attributes(RB_UNUSED_VAR(VALUE self), VALUE attributes)
389
443
  return rb_utf8_str_new_cstr("");
390
444
  }
391
445
 
392
- char *empty = "";
446
+ const char *empty = "";
393
447
  char *attrs = hash_value_to_attribute(empty, 0, attributes);
394
448
 
395
449
  VALUE rstring = rb_utf8_str_new_cstr(attrs);
@@ -398,7 +452,7 @@ static VALUE external_to_attributes(RB_UNUSED_VAR(VALUE self), VALUE attributes)
398
452
  return rstring;
399
453
  }
400
454
 
401
- static char * void_element(char *tag, size_t tlen, VALUE attributes) {
455
+ static char * void_element(const char *tag, size_t tlen, VALUE attributes) {
402
456
  /* T_IMEMO is what we get if an optional argument was not passed. */
403
457
  if (TYPE(attributes) == T_IMEMO) {
404
458
  size_t total = tag_olen + tlen + tag_clen + 1;
@@ -412,7 +466,7 @@ static char * void_element(char *tag, size_t tlen, VALUE attributes) {
412
466
 
413
467
  return string;
414
468
  } else {
415
- char *empty = "";
469
+ const char *empty = "";
416
470
  char *attrs = hash_value_to_attribute(empty, 0, attributes);
417
471
 
418
472
  size_t total = tag_olen + tlen + splen + strlen(attrs) + tag_clen + 1;
@@ -459,8 +513,8 @@ static VALUE external_void_element(int argc, VALUE *arguments, RB_UNUSED_VAR(VAL
459
513
  return rstring;
460
514
  }
461
515
 
462
- static char * element(char *tag, size_t tlen, char *content, size_t conlen, VALUE attributes) {
463
- char *empty = "";
516
+ static char * element(const char *tag, size_t tlen, char *content, size_t conlen, VALUE attributes) {
517
+ const char *empty = "";
464
518
  char *attrs = hash_value_to_attribute(empty, 0, attributes);
465
519
  size_t alen = strlen(attrs);
466
520
 
@@ -533,122 +587,123 @@ static VALUE external_element(int argc, VALUE *arguments, RB_UNUSED_VAR(VALUE se
533
587
  return rstring;
534
588
  }
535
589
 
536
- VOID_ELEMENT(area);
537
- VOID_ELEMENT(base);
538
- VOID_ELEMENT(br);
539
- VOID_ELEMENT(col);
540
- VOID_ELEMENT(embed);
541
- VOID_ELEMENT(hr);
542
- VOID_ELEMENT(img);
543
- VOID_ELEMENT(input);
544
- VOID_ELEMENT(link);
545
- VOID_ELEMENT(menuitem);
546
- VOID_ELEMENT(meta);
547
- VOID_ELEMENT(param);
548
- VOID_ELEMENT(source);
549
- VOID_ELEMENT(track);
550
- VOID_ELEMENT(wbr);
551
-
552
- STANDARD_ELEMENT(a);
553
- STANDARD_ELEMENT(abbr);
554
- STANDARD_ELEMENT(address);
555
- STANDARD_ELEMENT(article);
556
- STANDARD_ELEMENT(aside);
557
- STANDARD_ELEMENT(audio);
558
- STANDARD_ELEMENT(b);
559
- STANDARD_ELEMENT(bdi);
560
- STANDARD_ELEMENT(bdo);
561
- STANDARD_ELEMENT(blockquote);
562
- STANDARD_ELEMENT(body);
563
- STANDARD_ELEMENT(button);
564
- STANDARD_ELEMENT(canvas);
565
- STANDARD_ELEMENT(caption);
566
- STANDARD_ELEMENT(cite);
567
- STANDARD_ELEMENT(code);
568
- STANDARD_ELEMENT(colgroup);
569
- STANDARD_ELEMENT(datalist);
570
- STANDARD_ELEMENT(dd);
571
- STANDARD_ELEMENT(del);
572
- STANDARD_ELEMENT(details);
573
- STANDARD_ELEMENT(dfn);
574
- STANDARD_ELEMENT(dialog);
575
- STANDARD_ELEMENT(div);
576
- STANDARD_ELEMENT(dl);
577
- STANDARD_ELEMENT(dt);
578
- STANDARD_ELEMENT(em);
579
- STANDARD_ELEMENT(fieldset);
580
- STANDARD_ELEMENT(figcaption);
581
- STANDARD_ELEMENT(figure);
582
- STANDARD_ELEMENT(footer);
583
- STANDARD_ELEMENT(form);
584
- STANDARD_ELEMENT(h1);
585
- STANDARD_ELEMENT(h2);
586
- STANDARD_ELEMENT(h3);
587
- STANDARD_ELEMENT(h4);
588
- STANDARD_ELEMENT(h5);
589
- STANDARD_ELEMENT(h6);
590
- STANDARD_ELEMENT(head);
591
- STANDARD_ELEMENT(header);
592
- STANDARD_ELEMENT(html);
593
- STANDARD_ELEMENT(i);
594
- STANDARD_ELEMENT(iframe);
595
- STANDARD_ELEMENT(ins);
596
- STANDARD_ELEMENT(kbd);
597
- STANDARD_ELEMENT(label);
598
- STANDARD_ELEMENT(legend);
599
- STANDARD_ELEMENT(li);
600
- STANDARD_ELEMENT(main);
601
- STANDARD_ELEMENT(map);
602
- STANDARD_ELEMENT(mark);
603
- STANDARD_ELEMENT(menu);
604
- STANDARD_ELEMENT(meter);
605
- STANDARD_ELEMENT(nav);
606
- STANDARD_ELEMENT(noscript);
607
- STANDARD_ELEMENT(object);
608
- STANDARD_ELEMENT(ol);
609
- STANDARD_ELEMENT(optgroup);
610
- STANDARD_ELEMENT(option);
611
- STANDARD_ELEMENT(output);
612
- STANDARD_ELEMENT(p);
613
- STANDARD_ELEMENT(picture);
614
- STANDARD_ELEMENT(pre);
615
- STANDARD_ELEMENT(progress);
616
- STANDARD_ELEMENT(q);
617
- STANDARD_ELEMENT(rp);
618
- STANDARD_ELEMENT(rt);
619
- STANDARD_ELEMENT(ruby);
620
- STANDARD_ELEMENT(s);
621
- STANDARD_ELEMENT(samp);
622
- STANDARD_ELEMENT(script);
623
- STANDARD_ELEMENT(section);
624
- STANDARD_ELEMENT(select);
625
- STANDARD_ELEMENT(small);
626
- STANDARD_ELEMENT(span);
627
- STANDARD_ELEMENT(strong);
628
- STANDARD_ELEMENT(style);
629
- STANDARD_ELEMENT(sub);
630
- STANDARD_ELEMENT(summary);
631
- STANDARD_ELEMENT(table);
632
- STANDARD_ELEMENT(tbody);
633
- STANDARD_ELEMENT(td);
634
- STANDARD_ELEMENT(template);
635
- STANDARD_ELEMENT(textarea);
636
- STANDARD_ELEMENT(tfoot);
637
- STANDARD_ELEMENT(th);
638
- STANDARD_ELEMENT(thead);
639
- STANDARD_ELEMENT(time);
640
- STANDARD_ELEMENT(title);
641
- STANDARD_ELEMENT(tr);
642
- STANDARD_ELEMENT(u);
643
- STANDARD_ELEMENT(ul);
644
- STANDARD_ELEMENT(var);
645
- STANDARD_ELEMENT(video);
590
+ VOID_ELEMENT(area)
591
+ VOID_ELEMENT(base)
592
+ VOID_ELEMENT(br)
593
+ VOID_ELEMENT(col)
594
+ VOID_ELEMENT(embed)
595
+ VOID_ELEMENT(hr)
596
+ VOID_ELEMENT(img)
597
+ VOID_ELEMENT(input)
598
+ VOID_ELEMENT(link)
599
+ VOID_ELEMENT(menuitem)
600
+ VOID_ELEMENT(meta)
601
+ VOID_ELEMENT(param)
602
+ VOID_ELEMENT(source)
603
+ VOID_ELEMENT(track)
604
+ VOID_ELEMENT(wbr)
605
+
606
+ STANDARD_ELEMENT(a)
607
+ STANDARD_ELEMENT(abbr)
608
+ STANDARD_ELEMENT(address)
609
+ STANDARD_ELEMENT(article)
610
+ STANDARD_ELEMENT(aside)
611
+ STANDARD_ELEMENT(audio)
612
+ STANDARD_ELEMENT(b)
613
+ STANDARD_ELEMENT(bdi)
614
+ STANDARD_ELEMENT(bdo)
615
+ STANDARD_ELEMENT(blockquote)
616
+ STANDARD_ELEMENT(body)
617
+ STANDARD_ELEMENT(button)
618
+ STANDARD_ELEMENT(canvas)
619
+ STANDARD_ELEMENT(caption)
620
+ STANDARD_ELEMENT(cite)
621
+ STANDARD_ELEMENT(code)
622
+ STANDARD_ELEMENT(colgroup)
623
+ STANDARD_ELEMENT(datalist)
624
+ STANDARD_ELEMENT(dd)
625
+ STANDARD_ELEMENT(del)
626
+ STANDARD_ELEMENT(details)
627
+ STANDARD_ELEMENT(dfn)
628
+ STANDARD_ELEMENT(dialog)
629
+ STANDARD_ELEMENT(div)
630
+ STANDARD_ELEMENT(dl)
631
+ STANDARD_ELEMENT(dt)
632
+ STANDARD_ELEMENT(em)
633
+ STANDARD_ELEMENT(fieldset)
634
+ STANDARD_ELEMENT(figcaption)
635
+ STANDARD_ELEMENT(figure)
636
+ STANDARD_ELEMENT(footer)
637
+ STANDARD_ELEMENT(form)
638
+ STANDARD_ELEMENT(h1)
639
+ STANDARD_ELEMENT(h2)
640
+ STANDARD_ELEMENT(h3)
641
+ STANDARD_ELEMENT(h4)
642
+ STANDARD_ELEMENT(h5)
643
+ STANDARD_ELEMENT(h6)
644
+ STANDARD_ELEMENT(head)
645
+ STANDARD_ELEMENT(header)
646
+ STANDARD_ELEMENT(html)
647
+ STANDARD_ELEMENT(i)
648
+ STANDARD_ELEMENT(iframe)
649
+ STANDARD_ELEMENT(ins)
650
+ STANDARD_ELEMENT(kbd)
651
+ STANDARD_ELEMENT(label)
652
+ STANDARD_ELEMENT(legend)
653
+ STANDARD_ELEMENT(li)
654
+ STANDARD_ELEMENT(main)
655
+ STANDARD_ELEMENT(map)
656
+ STANDARD_ELEMENT(mark)
657
+ STANDARD_ELEMENT(menu)
658
+ STANDARD_ELEMENT(meter)
659
+ STANDARD_ELEMENT(nav)
660
+ STANDARD_ELEMENT(noscript)
661
+ STANDARD_ELEMENT(object)
662
+ STANDARD_ELEMENT(ol)
663
+ STANDARD_ELEMENT(optgroup)
664
+ STANDARD_ELEMENT(option)
665
+ STANDARD_ELEMENT(output)
666
+ STANDARD_ELEMENT(p)
667
+ STANDARD_ELEMENT(picture)
668
+ STANDARD_ELEMENT(pre)
669
+ STANDARD_ELEMENT(progress)
670
+ STANDARD_ELEMENT(q)
671
+ STANDARD_ELEMENT(rp)
672
+ STANDARD_ELEMENT(rt)
673
+ STANDARD_ELEMENT(ruby)
674
+ STANDARD_ELEMENT(s)
675
+ STANDARD_ELEMENT(samp)
676
+ STANDARD_ELEMENT(script)
677
+ STANDARD_ELEMENT(section)
678
+ STANDARD_ELEMENT(select)
679
+ STANDARD_ELEMENT(small)
680
+ STANDARD_ELEMENT(span)
681
+ STANDARD_ELEMENT(strong)
682
+ STANDARD_ELEMENT(style)
683
+ STANDARD_ELEMENT(sub)
684
+ STANDARD_ELEMENT(summary)
685
+ STANDARD_ELEMENT(table)
686
+ STANDARD_ELEMENT(tbody)
687
+ STANDARD_ELEMENT(td)
688
+ STANDARD_ELEMENT(template)
689
+ STANDARD_ELEMENT(textarea)
690
+ STANDARD_ELEMENT(tfoot)
691
+ STANDARD_ELEMENT(th)
692
+ STANDARD_ELEMENT(thead)
693
+ STANDARD_ELEMENT(time)
694
+ STANDARD_ELEMENT(title)
695
+ STANDARD_ELEMENT(tr)
696
+ STANDARD_ELEMENT(u)
697
+ STANDARD_ELEMENT(ul)
698
+ STANDARD_ELEMENT(var)
699
+ STANDARD_ELEMENT(video)
646
700
 
647
701
  void Init_berns() {
648
702
  VALUE Berns = rb_define_module("Berns");
649
703
 
650
704
  rb_define_singleton_method(Berns, "element", external_element, -1);
651
705
  rb_define_singleton_method(Berns, "escape_html", external_escape_html, 1);
706
+ rb_define_singleton_method(Berns, "sanitize", external_sanitize, 1);
652
707
  rb_define_singleton_method(Berns, "to_attribute", external_to_attribute, 2);
653
708
  rb_define_singleton_method(Berns, "to_attributes", external_to_attributes, 1);
654
709
  rb_define_singleton_method(Berns, "void", external_void_element, -1);
data/ext/berns/extconf.rb CHANGED
@@ -1,8 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
  require 'mkmf'
3
3
 
4
- $CFLAGS = '-O3 -msse4' # rubocop:disable Style/GlobalVars
4
+ dir_config 'berns'
5
+
6
+ append_cflags '-O3'
7
+ append_cflags '-Wshadow'
8
+ append_cflags '-Wstrict-overflow'
9
+ append_cflags '-flto'
10
+ append_cflags '-fno-strict-aliasing'
11
+ append_cflags '-msse4'
12
+ append_cflags '-std=c99'
5
13
 
6
- dir_config('berns')
7
- create_header
8
14
  create_makefile 'berns/berns'
data/lib/berns.rb CHANGED
@@ -1,25 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
  require 'berns/berns'
3
3
  require 'berns/version'
4
-
5
- module Berns # :nodoc:
6
- class Error < StandardError; end
7
-
8
- EMPTY = ''
9
-
10
- # Regular expression for basic HTML tag sanitizing.
11
- SANITIZE_REGEX = /<[^>]+>/.freeze
12
-
13
- # Sanitize text input by stripping HTML tags.
14
- #
15
- # @example Sanitize some text, removing HTML elements.
16
- # sanitize('This <span>should be clean</span>') # => "This should be clean"
17
- #
18
- # @param text [String]
19
- # The string to sanitize.
20
- # @return [nil, String]
21
- # nil unless a string was passed in, otherwise the sanitized string.
22
- def self.sanitize(string)
23
- string&.gsub(SANITIZE_REGEX, EMPTY)
24
- end
25
- end
data/lib/berns/berns.so CHANGED
Binary file
data/lib/berns/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Berns
3
- VERSION = '3.1.4'
3
+ VERSION = '3.3.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berns
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.4
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Beck
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-05-17 00:00:00.000000000 Z
12
+ date: 2021-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: benchmark-ips