berns 3.1.3 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.org +4 -0
- data/ext/berns/berns.c +199 -154
- data/ext/berns/extconf.rb +9 -3
- data/lib/berns.rb +0 -22
- data/lib/berns/berns.so +0 -0
- data/lib/berns/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74e861ab5e3bfb8359f063dc7637b4f9c8f30ed60722b3f6cfec7aaf432915af
|
4
|
+
data.tar.gz: 17e884c022d55c44ad4ff080ec485d82688664529aee4d656b95d1d93a129e31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17166b6a903fba75f3cf3984710735e92206892eec6310bb2144ff5e088694089326426baf2c8e7c1246e681d4887559f01f7364635bfc29006878a908b9912f
|
7
|
+
data.tar.gz: 9472135003033d1fdc6db413e44cf7ab69be6fa947b9e2a452d2bd24f316f0708055d03d6157adf292c5b9644d73dd08cad261c1b4c45588be18b8069e5366e2
|
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,11 +46,11 @@ 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*
|
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; \
|
54
|
-
char *string = void_element(tag, strlen(tag),
|
52
|
+
const char *tag = #element_name; \
|
53
|
+
char *string = void_element(tag, strlen(tag), argv[0]); \
|
55
54
|
VALUE rstring = rb_utf8_str_new_cstr(string); \
|
56
55
|
free(string); \
|
57
56
|
\
|
@@ -62,12 +61,12 @@ 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*
|
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; \
|
70
|
-
char *string = element(tag, strlen(tag), RSTRING_PTR(content), RSTRING_LEN(content),
|
68
|
+
const char *tag = #element_name; \
|
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); \
|
73
72
|
\
|
@@ -78,25 +77,74 @@ 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
|
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
|
+
int index = 0;
|
114
|
+
int open = 0;
|
115
|
+
int opened = 0;
|
116
|
+
|
117
|
+
for (unsigned int i = 0; i < slen; i++) {
|
118
|
+
if (str[i] == '<') {
|
119
|
+
open = 1;
|
120
|
+
opened = 1;
|
121
|
+
} else if (str[i] == '>') {
|
122
|
+
open = 0;
|
123
|
+
} else if (!open) {
|
124
|
+
dest[index++] = str[i];
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
dest[index] = '\0';
|
129
|
+
|
130
|
+
/*
|
131
|
+
* If a tag was never opened, return the original string, otherwise create a new
|
132
|
+
* string from our destination buffer.
|
133
|
+
*/
|
134
|
+
if (opened) {
|
135
|
+
return rb_utf8_str_new_cstr(dest);
|
136
|
+
} else {
|
137
|
+
return string;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
93
141
|
/*
|
94
142
|
* The external API for Berns.escape_html.
|
95
143
|
*
|
96
144
|
* string should be a string, anything else will raise an error.
|
97
145
|
*
|
98
146
|
*/
|
99
|
-
static VALUE external_escape_html(
|
147
|
+
static VALUE external_escape_html(RB_UNUSED_VAR(VALUE self), VALUE string) {
|
100
148
|
StringValue(string);
|
101
149
|
|
102
150
|
uint8_t *dest = NULL;
|
@@ -123,7 +171,6 @@ static VALUE external_escape_html(const VALUE self, VALUE string) {
|
|
123
171
|
static char * empty_value_to_attribute(const char *attr, const size_t attrlen) {
|
124
172
|
size_t total_size = attrlen + 1;
|
125
173
|
char *dest = malloc(total_size);
|
126
|
-
char *ptr = NULL;
|
127
174
|
char *end = dest + total_size;
|
128
175
|
|
129
176
|
stecpy(dest, attr, end);
|
@@ -140,7 +187,6 @@ static char * string_value_to_attribute(const char *attr, const size_t attrlen,
|
|
140
187
|
if (vallen == 0) {
|
141
188
|
size_t total_size = attrlen + 1;
|
142
189
|
char *dest = malloc(total_size);
|
143
|
-
char *ptr = NULL;
|
144
190
|
char *end = dest + total_size;
|
145
191
|
|
146
192
|
stecpy(dest, attr, end);
|
@@ -168,21 +214,21 @@ static char * string_value_to_attribute(const char *attr, const size_t attrlen,
|
|
168
214
|
}
|
169
215
|
}
|
170
216
|
|
171
|
-
static char * hash_value_to_attribute(char *attr, const size_t attrlen, VALUE
|
172
|
-
if (TYPE(
|
217
|
+
static char * hash_value_to_attribute(const char *attr, const size_t attrlen, VALUE value) {
|
218
|
+
if (TYPE(value) == T_IMEMO) {
|
173
219
|
return strdup("");
|
174
220
|
}
|
175
221
|
|
176
|
-
Check_Type(
|
222
|
+
Check_Type(value, T_HASH);
|
177
223
|
|
178
|
-
if (rb_hash_size(
|
224
|
+
if (rb_hash_size(value) == 1) {
|
179
225
|
return strdup("");
|
180
226
|
}
|
181
227
|
|
182
228
|
VALUE subkey;
|
183
229
|
VALUE subvalue;
|
184
230
|
|
185
|
-
const VALUE keys = rb_funcall(
|
231
|
+
const VALUE keys = rb_funcall(value, rb_intern("keys"), 0);
|
186
232
|
const VALUE length = RARRAY_LEN(keys);
|
187
233
|
|
188
234
|
size_t allocated = 256;
|
@@ -194,7 +240,7 @@ static char * hash_value_to_attribute(char *attr, const size_t attrlen, VALUE *v
|
|
194
240
|
|
195
241
|
for (unsigned int i = 0; i < length; i++) {
|
196
242
|
subkey = rb_ary_entry(keys, i);
|
197
|
-
subvalue = rb_hash_aref(
|
243
|
+
subvalue = rb_hash_aref(value, subkey);
|
198
244
|
|
199
245
|
switch(TYPE(subkey)) {
|
200
246
|
case T_STRING:
|
@@ -224,17 +270,17 @@ static char * hash_value_to_attribute(char *attr, const size_t attrlen, VALUE *v
|
|
224
270
|
|
225
271
|
char subattr[subattr_len + 1];
|
226
272
|
char *ptr = subattr;
|
227
|
-
char *
|
273
|
+
char *subend = subattr + subattr_len + 1;
|
228
274
|
|
229
275
|
if (attrlen > 0) {
|
230
|
-
ptr = stecpy(ptr, attr,
|
276
|
+
ptr = stecpy(ptr, attr, subend);
|
231
277
|
}
|
232
278
|
|
233
279
|
if (attrlen > 0 && subkey_len > 0) {
|
234
|
-
ptr = stecpy(ptr, dash,
|
280
|
+
ptr = stecpy(ptr, dash, subend);
|
235
281
|
}
|
236
282
|
|
237
|
-
stecpy(ptr, RSTRING_PTR(subkey),
|
283
|
+
stecpy(ptr, RSTRING_PTR(subkey), subend);
|
238
284
|
|
239
285
|
char *combined;
|
240
286
|
|
@@ -243,8 +289,10 @@ static char * hash_value_to_attribute(char *attr, const size_t attrlen, VALUE *v
|
|
243
289
|
combined = strdup("");
|
244
290
|
break;
|
245
291
|
|
292
|
+
case T_NIL:
|
293
|
+
/* Fall through. */
|
246
294
|
case T_TRUE:
|
247
|
-
combined =
|
295
|
+
combined = empty_value_to_attribute(subattr, subattr_len);
|
248
296
|
break;
|
249
297
|
|
250
298
|
case T_STRING:
|
@@ -256,13 +304,8 @@ static char * hash_value_to_attribute(char *attr, const size_t attrlen, VALUE *v
|
|
256
304
|
combined = string_value_to_attribute(subattr, subattr_len, RSTRING_PTR(subvalue), RSTRING_LEN(subvalue));
|
257
305
|
break;
|
258
306
|
|
259
|
-
case T_NIL:
|
260
|
-
subvalue = rb_utf8_str_new_cstr("");
|
261
|
-
combined = string_value_to_attribute(subattr, subattr_len, RSTRING_PTR(subvalue), RSTRING_LEN(subvalue));
|
262
|
-
break;
|
263
|
-
|
264
307
|
case T_HASH:
|
265
|
-
combined = hash_value_to_attribute(subattr, subattr_len,
|
308
|
+
combined = hash_value_to_attribute(subattr, subattr_len, subvalue);
|
266
309
|
break;
|
267
310
|
|
268
311
|
default:
|
@@ -313,7 +356,7 @@ static char * hash_value_to_attribute(char *attr, const size_t attrlen, VALUE *v
|
|
313
356
|
/*
|
314
357
|
* Convert an attribute name and value into a string.
|
315
358
|
*/
|
316
|
-
static char * to_attribute(VALUE attr, VALUE
|
359
|
+
static char * to_attribute(VALUE attr, VALUE value) {
|
317
360
|
switch(TYPE(attr)) {
|
318
361
|
case T_SYMBOL:
|
319
362
|
attr = rb_sym2str(attr);
|
@@ -327,8 +370,9 @@ static char * to_attribute(VALUE attr, VALUE *value) {
|
|
327
370
|
char *val = NULL;
|
328
371
|
VALUE str;
|
329
372
|
|
330
|
-
switch(TYPE(
|
373
|
+
switch(TYPE(value)) {
|
331
374
|
case T_NIL:
|
375
|
+
/* Fall through. */
|
332
376
|
case T_TRUE:
|
333
377
|
val = empty_value_to_attribute(RSTRING_PTR(attr), RSTRING_LEN(attr));
|
334
378
|
break;
|
@@ -339,14 +383,14 @@ static char * to_attribute(VALUE attr, VALUE *value) {
|
|
339
383
|
val = hash_value_to_attribute(RSTRING_PTR(attr), RSTRING_LEN(attr), value);
|
340
384
|
break;
|
341
385
|
case T_STRING:
|
342
|
-
val = string_value_to_attribute(RSTRING_PTR(attr), RSTRING_LEN(attr), RSTRING_PTR(
|
386
|
+
val = string_value_to_attribute(RSTRING_PTR(attr), RSTRING_LEN(attr), RSTRING_PTR(value), RSTRING_LEN(value));
|
343
387
|
break;
|
344
388
|
case T_SYMBOL:
|
345
|
-
str = rb_sym2str(
|
389
|
+
str = rb_sym2str(value);
|
346
390
|
val = string_value_to_attribute(RSTRING_PTR(attr), RSTRING_LEN(attr), RSTRING_PTR(str), RSTRING_LEN(str));
|
347
391
|
break;
|
348
392
|
default:
|
349
|
-
str = rb_funcall(
|
393
|
+
str = rb_funcall(value, rb_intern("to_s"), 0);
|
350
394
|
val = string_value_to_attribute(RSTRING_PTR(attr), RSTRING_LEN(attr), RSTRING_PTR(str), RSTRING_LEN(str));
|
351
395
|
break;
|
352
396
|
}
|
@@ -372,7 +416,7 @@ static VALUE external_to_attribute(RB_UNUSED_VAR(VALUE self), VALUE attr, VALUE
|
|
372
416
|
|
373
417
|
StringValue(attr);
|
374
418
|
|
375
|
-
char *val = to_attribute(attr,
|
419
|
+
char *val = to_attribute(attr, value);
|
376
420
|
VALUE rstring = rb_utf8_str_new_cstr(val);
|
377
421
|
free(val);
|
378
422
|
|
@@ -392,8 +436,8 @@ static VALUE external_to_attributes(RB_UNUSED_VAR(VALUE self), VALUE attributes)
|
|
392
436
|
return rb_utf8_str_new_cstr("");
|
393
437
|
}
|
394
438
|
|
395
|
-
char *empty = "";
|
396
|
-
char *attrs = hash_value_to_attribute(empty, 0,
|
439
|
+
const char *empty = "";
|
440
|
+
char *attrs = hash_value_to_attribute(empty, 0, attributes);
|
397
441
|
|
398
442
|
VALUE rstring = rb_utf8_str_new_cstr(attrs);
|
399
443
|
free(attrs);
|
@@ -401,9 +445,9 @@ static VALUE external_to_attributes(RB_UNUSED_VAR(VALUE self), VALUE attributes)
|
|
401
445
|
return rstring;
|
402
446
|
}
|
403
447
|
|
404
|
-
static char * void_element(char *tag, size_t tlen, VALUE
|
448
|
+
static char * void_element(const char *tag, size_t tlen, VALUE attributes) {
|
405
449
|
/* T_IMEMO is what we get if an optional argument was not passed. */
|
406
|
-
if (TYPE(
|
450
|
+
if (TYPE(attributes) == T_IMEMO) {
|
407
451
|
size_t total = tag_olen + tlen + tag_clen + 1;
|
408
452
|
char *string = malloc(total);
|
409
453
|
char *ptr;
|
@@ -415,7 +459,7 @@ static char * void_element(char *tag, size_t tlen, VALUE *attributes) {
|
|
415
459
|
|
416
460
|
return string;
|
417
461
|
} else {
|
418
|
-
char *empty = "";
|
462
|
+
const char *empty = "";
|
419
463
|
char *attrs = hash_value_to_attribute(empty, 0, attributes);
|
420
464
|
|
421
465
|
size_t total = tag_olen + tlen + splen + strlen(attrs) + tag_clen + 1;
|
@@ -454,7 +498,7 @@ static VALUE external_void_element(int argc, VALUE *arguments, RB_UNUSED_VAR(VAL
|
|
454
498
|
|
455
499
|
StringValue(tag);
|
456
500
|
|
457
|
-
char *string = void_element(RSTRING_PTR(tag), RSTRING_LEN(tag),
|
501
|
+
char *string = void_element(RSTRING_PTR(tag), RSTRING_LEN(tag), attributes);
|
458
502
|
VALUE rstring = rb_utf8_str_new_cstr(string);
|
459
503
|
|
460
504
|
free(string);
|
@@ -462,8 +506,8 @@ static VALUE external_void_element(int argc, VALUE *arguments, RB_UNUSED_VAR(VAL
|
|
462
506
|
return rstring;
|
463
507
|
}
|
464
508
|
|
465
|
-
static char * element(char *tag, size_t tlen, char *content, size_t conlen, VALUE
|
466
|
-
char *empty = "";
|
509
|
+
static char * element(const char *tag, size_t tlen, char *content, size_t conlen, VALUE attributes) {
|
510
|
+
const char *empty = "";
|
467
511
|
char *attrs = hash_value_to_attribute(empty, 0, attributes);
|
468
512
|
size_t alen = strlen(attrs);
|
469
513
|
|
@@ -529,129 +573,130 @@ static VALUE external_element(int argc, VALUE *arguments, RB_UNUSED_VAR(VALUE se
|
|
529
573
|
|
530
574
|
CONTENT_FROM_BLOCK;
|
531
575
|
|
532
|
-
char *string = element(RSTRING_PTR(tag), RSTRING_LEN(tag), RSTRING_PTR(content), RSTRING_LEN(content),
|
576
|
+
char *string = element(RSTRING_PTR(tag), RSTRING_LEN(tag), RSTRING_PTR(content), RSTRING_LEN(content), attributes);
|
533
577
|
VALUE rstring = rb_utf8_str_new_cstr(string);
|
534
578
|
free(string);
|
535
579
|
|
536
580
|
return rstring;
|
537
581
|
}
|
538
582
|
|
539
|
-
VOID_ELEMENT(area)
|
540
|
-
VOID_ELEMENT(base)
|
541
|
-
VOID_ELEMENT(br)
|
542
|
-
VOID_ELEMENT(col)
|
543
|
-
VOID_ELEMENT(embed)
|
544
|
-
VOID_ELEMENT(hr)
|
545
|
-
VOID_ELEMENT(img)
|
546
|
-
VOID_ELEMENT(input)
|
547
|
-
VOID_ELEMENT(link)
|
548
|
-
VOID_ELEMENT(menuitem)
|
549
|
-
VOID_ELEMENT(meta)
|
550
|
-
VOID_ELEMENT(param)
|
551
|
-
VOID_ELEMENT(source)
|
552
|
-
VOID_ELEMENT(track)
|
553
|
-
VOID_ELEMENT(wbr)
|
554
|
-
|
555
|
-
STANDARD_ELEMENT(a)
|
556
|
-
STANDARD_ELEMENT(abbr)
|
557
|
-
STANDARD_ELEMENT(address)
|
558
|
-
STANDARD_ELEMENT(article)
|
559
|
-
STANDARD_ELEMENT(aside)
|
560
|
-
STANDARD_ELEMENT(audio)
|
561
|
-
STANDARD_ELEMENT(b)
|
562
|
-
STANDARD_ELEMENT(bdi)
|
563
|
-
STANDARD_ELEMENT(bdo)
|
564
|
-
STANDARD_ELEMENT(blockquote)
|
565
|
-
STANDARD_ELEMENT(body)
|
566
|
-
STANDARD_ELEMENT(button)
|
567
|
-
STANDARD_ELEMENT(canvas)
|
568
|
-
STANDARD_ELEMENT(caption)
|
569
|
-
STANDARD_ELEMENT(cite)
|
570
|
-
STANDARD_ELEMENT(code)
|
571
|
-
STANDARD_ELEMENT(colgroup)
|
572
|
-
STANDARD_ELEMENT(datalist)
|
573
|
-
STANDARD_ELEMENT(dd)
|
574
|
-
STANDARD_ELEMENT(del)
|
575
|
-
STANDARD_ELEMENT(details)
|
576
|
-
STANDARD_ELEMENT(dfn)
|
577
|
-
STANDARD_ELEMENT(dialog)
|
578
|
-
STANDARD_ELEMENT(div)
|
579
|
-
STANDARD_ELEMENT(dl)
|
580
|
-
STANDARD_ELEMENT(dt)
|
581
|
-
STANDARD_ELEMENT(em)
|
582
|
-
STANDARD_ELEMENT(fieldset)
|
583
|
-
STANDARD_ELEMENT(figcaption)
|
584
|
-
STANDARD_ELEMENT(figure)
|
585
|
-
STANDARD_ELEMENT(footer)
|
586
|
-
STANDARD_ELEMENT(form)
|
587
|
-
STANDARD_ELEMENT(h1)
|
588
|
-
STANDARD_ELEMENT(h2)
|
589
|
-
STANDARD_ELEMENT(h3)
|
590
|
-
STANDARD_ELEMENT(h4)
|
591
|
-
STANDARD_ELEMENT(h5)
|
592
|
-
STANDARD_ELEMENT(h6)
|
593
|
-
STANDARD_ELEMENT(head)
|
594
|
-
STANDARD_ELEMENT(header)
|
595
|
-
STANDARD_ELEMENT(html)
|
596
|
-
STANDARD_ELEMENT(i)
|
597
|
-
STANDARD_ELEMENT(iframe)
|
598
|
-
STANDARD_ELEMENT(ins)
|
599
|
-
STANDARD_ELEMENT(kbd)
|
600
|
-
STANDARD_ELEMENT(label)
|
601
|
-
STANDARD_ELEMENT(legend)
|
602
|
-
STANDARD_ELEMENT(li)
|
603
|
-
STANDARD_ELEMENT(main)
|
604
|
-
STANDARD_ELEMENT(map)
|
605
|
-
STANDARD_ELEMENT(mark)
|
606
|
-
STANDARD_ELEMENT(menu)
|
607
|
-
STANDARD_ELEMENT(meter)
|
608
|
-
STANDARD_ELEMENT(nav)
|
609
|
-
STANDARD_ELEMENT(noscript)
|
610
|
-
STANDARD_ELEMENT(object)
|
611
|
-
STANDARD_ELEMENT(ol)
|
612
|
-
STANDARD_ELEMENT(optgroup)
|
613
|
-
STANDARD_ELEMENT(option)
|
614
|
-
STANDARD_ELEMENT(output)
|
615
|
-
STANDARD_ELEMENT(p)
|
616
|
-
STANDARD_ELEMENT(picture)
|
617
|
-
STANDARD_ELEMENT(pre)
|
618
|
-
STANDARD_ELEMENT(progress)
|
619
|
-
STANDARD_ELEMENT(q)
|
620
|
-
STANDARD_ELEMENT(rp)
|
621
|
-
STANDARD_ELEMENT(rt)
|
622
|
-
STANDARD_ELEMENT(ruby)
|
623
|
-
STANDARD_ELEMENT(s)
|
624
|
-
STANDARD_ELEMENT(samp)
|
625
|
-
STANDARD_ELEMENT(script)
|
626
|
-
STANDARD_ELEMENT(section)
|
627
|
-
STANDARD_ELEMENT(select)
|
628
|
-
STANDARD_ELEMENT(small)
|
629
|
-
STANDARD_ELEMENT(span)
|
630
|
-
STANDARD_ELEMENT(strong)
|
631
|
-
STANDARD_ELEMENT(style)
|
632
|
-
STANDARD_ELEMENT(sub)
|
633
|
-
STANDARD_ELEMENT(summary)
|
634
|
-
STANDARD_ELEMENT(table)
|
635
|
-
STANDARD_ELEMENT(tbody)
|
636
|
-
STANDARD_ELEMENT(td)
|
637
|
-
STANDARD_ELEMENT(template)
|
638
|
-
STANDARD_ELEMENT(textarea)
|
639
|
-
STANDARD_ELEMENT(tfoot)
|
640
|
-
STANDARD_ELEMENT(th)
|
641
|
-
STANDARD_ELEMENT(thead)
|
642
|
-
STANDARD_ELEMENT(time)
|
643
|
-
STANDARD_ELEMENT(title)
|
644
|
-
STANDARD_ELEMENT(tr)
|
645
|
-
STANDARD_ELEMENT(u)
|
646
|
-
STANDARD_ELEMENT(ul)
|
647
|
-
STANDARD_ELEMENT(var)
|
648
|
-
STANDARD_ELEMENT(video)
|
583
|
+
VOID_ELEMENT(area)
|
584
|
+
VOID_ELEMENT(base)
|
585
|
+
VOID_ELEMENT(br)
|
586
|
+
VOID_ELEMENT(col)
|
587
|
+
VOID_ELEMENT(embed)
|
588
|
+
VOID_ELEMENT(hr)
|
589
|
+
VOID_ELEMENT(img)
|
590
|
+
VOID_ELEMENT(input)
|
591
|
+
VOID_ELEMENT(link)
|
592
|
+
VOID_ELEMENT(menuitem)
|
593
|
+
VOID_ELEMENT(meta)
|
594
|
+
VOID_ELEMENT(param)
|
595
|
+
VOID_ELEMENT(source)
|
596
|
+
VOID_ELEMENT(track)
|
597
|
+
VOID_ELEMENT(wbr)
|
598
|
+
|
599
|
+
STANDARD_ELEMENT(a)
|
600
|
+
STANDARD_ELEMENT(abbr)
|
601
|
+
STANDARD_ELEMENT(address)
|
602
|
+
STANDARD_ELEMENT(article)
|
603
|
+
STANDARD_ELEMENT(aside)
|
604
|
+
STANDARD_ELEMENT(audio)
|
605
|
+
STANDARD_ELEMENT(b)
|
606
|
+
STANDARD_ELEMENT(bdi)
|
607
|
+
STANDARD_ELEMENT(bdo)
|
608
|
+
STANDARD_ELEMENT(blockquote)
|
609
|
+
STANDARD_ELEMENT(body)
|
610
|
+
STANDARD_ELEMENT(button)
|
611
|
+
STANDARD_ELEMENT(canvas)
|
612
|
+
STANDARD_ELEMENT(caption)
|
613
|
+
STANDARD_ELEMENT(cite)
|
614
|
+
STANDARD_ELEMENT(code)
|
615
|
+
STANDARD_ELEMENT(colgroup)
|
616
|
+
STANDARD_ELEMENT(datalist)
|
617
|
+
STANDARD_ELEMENT(dd)
|
618
|
+
STANDARD_ELEMENT(del)
|
619
|
+
STANDARD_ELEMENT(details)
|
620
|
+
STANDARD_ELEMENT(dfn)
|
621
|
+
STANDARD_ELEMENT(dialog)
|
622
|
+
STANDARD_ELEMENT(div)
|
623
|
+
STANDARD_ELEMENT(dl)
|
624
|
+
STANDARD_ELEMENT(dt)
|
625
|
+
STANDARD_ELEMENT(em)
|
626
|
+
STANDARD_ELEMENT(fieldset)
|
627
|
+
STANDARD_ELEMENT(figcaption)
|
628
|
+
STANDARD_ELEMENT(figure)
|
629
|
+
STANDARD_ELEMENT(footer)
|
630
|
+
STANDARD_ELEMENT(form)
|
631
|
+
STANDARD_ELEMENT(h1)
|
632
|
+
STANDARD_ELEMENT(h2)
|
633
|
+
STANDARD_ELEMENT(h3)
|
634
|
+
STANDARD_ELEMENT(h4)
|
635
|
+
STANDARD_ELEMENT(h5)
|
636
|
+
STANDARD_ELEMENT(h6)
|
637
|
+
STANDARD_ELEMENT(head)
|
638
|
+
STANDARD_ELEMENT(header)
|
639
|
+
STANDARD_ELEMENT(html)
|
640
|
+
STANDARD_ELEMENT(i)
|
641
|
+
STANDARD_ELEMENT(iframe)
|
642
|
+
STANDARD_ELEMENT(ins)
|
643
|
+
STANDARD_ELEMENT(kbd)
|
644
|
+
STANDARD_ELEMENT(label)
|
645
|
+
STANDARD_ELEMENT(legend)
|
646
|
+
STANDARD_ELEMENT(li)
|
647
|
+
STANDARD_ELEMENT(main)
|
648
|
+
STANDARD_ELEMENT(map)
|
649
|
+
STANDARD_ELEMENT(mark)
|
650
|
+
STANDARD_ELEMENT(menu)
|
651
|
+
STANDARD_ELEMENT(meter)
|
652
|
+
STANDARD_ELEMENT(nav)
|
653
|
+
STANDARD_ELEMENT(noscript)
|
654
|
+
STANDARD_ELEMENT(object)
|
655
|
+
STANDARD_ELEMENT(ol)
|
656
|
+
STANDARD_ELEMENT(optgroup)
|
657
|
+
STANDARD_ELEMENT(option)
|
658
|
+
STANDARD_ELEMENT(output)
|
659
|
+
STANDARD_ELEMENT(p)
|
660
|
+
STANDARD_ELEMENT(picture)
|
661
|
+
STANDARD_ELEMENT(pre)
|
662
|
+
STANDARD_ELEMENT(progress)
|
663
|
+
STANDARD_ELEMENT(q)
|
664
|
+
STANDARD_ELEMENT(rp)
|
665
|
+
STANDARD_ELEMENT(rt)
|
666
|
+
STANDARD_ELEMENT(ruby)
|
667
|
+
STANDARD_ELEMENT(s)
|
668
|
+
STANDARD_ELEMENT(samp)
|
669
|
+
STANDARD_ELEMENT(script)
|
670
|
+
STANDARD_ELEMENT(section)
|
671
|
+
STANDARD_ELEMENT(select)
|
672
|
+
STANDARD_ELEMENT(small)
|
673
|
+
STANDARD_ELEMENT(span)
|
674
|
+
STANDARD_ELEMENT(strong)
|
675
|
+
STANDARD_ELEMENT(style)
|
676
|
+
STANDARD_ELEMENT(sub)
|
677
|
+
STANDARD_ELEMENT(summary)
|
678
|
+
STANDARD_ELEMENT(table)
|
679
|
+
STANDARD_ELEMENT(tbody)
|
680
|
+
STANDARD_ELEMENT(td)
|
681
|
+
STANDARD_ELEMENT(template)
|
682
|
+
STANDARD_ELEMENT(textarea)
|
683
|
+
STANDARD_ELEMENT(tfoot)
|
684
|
+
STANDARD_ELEMENT(th)
|
685
|
+
STANDARD_ELEMENT(thead)
|
686
|
+
STANDARD_ELEMENT(time)
|
687
|
+
STANDARD_ELEMENT(title)
|
688
|
+
STANDARD_ELEMENT(tr)
|
689
|
+
STANDARD_ELEMENT(u)
|
690
|
+
STANDARD_ELEMENT(ul)
|
691
|
+
STANDARD_ELEMENT(var)
|
692
|
+
STANDARD_ELEMENT(video)
|
649
693
|
|
650
694
|
void Init_berns() {
|
651
695
|
VALUE Berns = rb_define_module("Berns");
|
652
696
|
|
653
697
|
rb_define_singleton_method(Berns, "element", external_element, -1);
|
654
698
|
rb_define_singleton_method(Berns, "escape_html", external_escape_html, 1);
|
699
|
+
rb_define_singleton_method(Berns, "sanitize", external_sanitize, 1);
|
655
700
|
rb_define_singleton_method(Berns, "to_attribute", external_to_attribute, 2);
|
656
701
|
rb_define_singleton_method(Berns, "to_attributes", external_to_attributes, 1);
|
657
702
|
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
|
-
|
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
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
|
+
version: 3.2.1
|
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-
|
12
|
+
date: 2021-06-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: benchmark-ips
|