berns 3.1.6 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +15 -16
- data/README.org +9 -0
- data/ext/berns/berns.c +58 -7
- data/ext/berns/extconf.rb +0 -1
- data/lib/berns/berns.bundle +0 -0
- data/lib/berns/version.rb +1 -1
- data/lib/berns.rb +0 -22
- metadata +9 -8
- data/lib/berns/berns.so +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8befdd27a627569fd4d81d583c107e97af40e9b8f29423c4178fffa1decb92e9
|
4
|
+
data.tar.gz: e268d19c3fafd596d310fefddcda6e9ca2393f06f668d52c3d92a7d748e41c77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d14dbff87be26716aa466fab088ac036e25e27e72fd2893c4fb67f02422560c88d8bd2d15c08b176c6c9b4fa706ed3a4098edcfe54af273a43eef5cacd295142
|
7
|
+
data.tar.gz: 34c7b95ee33095ea4e8712e280ad90cfe7d79d983996c72c0c245bb63ee9c10c28150a8bfbc3da0f56236ec5ac7df35f61a11f1f4a5e5f0255c167896e4bae5c
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
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
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
@@ -114,3 +118,8 @@ Berns.
|
|
114
118
|
#+begin_example
|
115
119
|
area base br col embed hr img input link menuitem meta param source track wbr
|
116
120
|
#+end_example
|
121
|
+
|
122
|
+
** Trivia
|
123
|
+
|
124
|
+
The name "Berns" is taken from the name of [[https://en.wikipedia.org/wiki/HTML#Development][the inventor of HTML]], [[https://en.wikipedia.org/wiki/Tim_Berners-Lee][Sir Tim
|
125
|
+
Berners-Lee]].
|
data/ext/berns/berns.c
CHANGED
@@ -49,9 +49,8 @@ static const size_t sllen = 1;
|
|
49
49
|
static VALUE external_##element_name##_element(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self)) { \
|
50
50
|
rb_check_arity(argc, 0, 1); \
|
51
51
|
\
|
52
|
-
VALUE attrs = argv[0]; \
|
53
52
|
const char *tag = #element_name; \
|
54
|
-
char *string = void_element(tag, strlen(tag),
|
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
|
\
|
@@ -65,10 +64,9 @@ static const size_t sllen = 1;
|
|
65
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
|
-
CONTENT_FROM_BLOCK
|
69
|
-
VALUE attrs = argv[0]; \
|
67
|
+
CONTENT_FROM_BLOCK \
|
70
68
|
const char *tag = #element_name; \
|
71
|
-
char *string = element(tag, strlen(tag), RSTRING_PTR(content), RSTRING_LEN(content),
|
69
|
+
char *string = element(tag, strlen(tag), RSTRING_PTR(content), RSTRING_LEN(content), argv[0]); \
|
72
70
|
VALUE rstring = rb_utf8_str_new_cstr(string); \
|
73
71
|
free(string); \
|
74
72
|
\
|
@@ -95,13 +93,65 @@ static char * stecpy(char *destination, const char *source, const char *end) {
|
|
95
93
|
return destination;
|
96
94
|
}
|
97
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
|
+
|
98
148
|
/*
|
99
149
|
* The external API for Berns.escape_html.
|
100
150
|
*
|
101
151
|
* string should be a string, anything else will raise an error.
|
102
152
|
*
|
103
153
|
*/
|
104
|
-
static VALUE external_escape_html(
|
154
|
+
static VALUE external_escape_html(RB_UNUSED_VAR(VALUE self), VALUE string) {
|
105
155
|
StringValue(string);
|
106
156
|
|
107
157
|
uint8_t *dest = NULL;
|
@@ -528,7 +578,7 @@ static VALUE external_element(int argc, VALUE *arguments, RB_UNUSED_VAR(VALUE se
|
|
528
578
|
|
529
579
|
StringValue(tag);
|
530
580
|
|
531
|
-
CONTENT_FROM_BLOCK
|
581
|
+
CONTENT_FROM_BLOCK
|
532
582
|
|
533
583
|
char *string = element(RSTRING_PTR(tag), RSTRING_LEN(tag), RSTRING_PTR(content), RSTRING_LEN(content), attributes);
|
534
584
|
VALUE rstring = rb_utf8_str_new_cstr(string);
|
@@ -653,6 +703,7 @@ void Init_berns() {
|
|
653
703
|
|
654
704
|
rb_define_singleton_method(Berns, "element", external_element, -1);
|
655
705
|
rb_define_singleton_method(Berns, "escape_html", external_escape_html, 1);
|
706
|
+
rb_define_singleton_method(Berns, "sanitize", external_sanitize, 1);
|
656
707
|
rb_define_singleton_method(Berns, "to_attribute", external_to_attribute, 2);
|
657
708
|
rb_define_singleton_method(Berns, "to_attributes", external_to_attributes, 1);
|
658
709
|
rb_define_singleton_method(Berns, "void", external_void_element, -1);
|
data/ext/berns/extconf.rb
CHANGED
Binary file
|
data/lib/berns/version.rb
CHANGED
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
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: berns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1
|
4
|
+
version: 3.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Beck
|
8
8
|
- Evan Lecklider
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-12-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: benchmark-ips
|
@@ -167,15 +167,16 @@ files:
|
|
167
167
|
- ext/berns/hescape.c
|
168
168
|
- ext/berns/hescape.h
|
169
169
|
- lib/berns.rb
|
170
|
-
- lib/berns/berns.
|
170
|
+
- lib/berns/berns.bundle
|
171
171
|
- lib/berns/version.rb
|
172
172
|
homepage: https://github.com/evanleck/berns
|
173
173
|
licenses:
|
174
174
|
- MIT
|
175
175
|
metadata:
|
176
176
|
bug_tracker_uri: https://github.com/evanleck/berns/issues
|
177
|
+
rubygems_mfa_required: 'true'
|
177
178
|
source_code_uri: https://github.com/evanleck/berns
|
178
|
-
post_install_message:
|
179
|
+
post_install_message:
|
179
180
|
rdoc_options: []
|
180
181
|
require_paths:
|
181
182
|
- lib
|
@@ -188,10 +189,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
189
|
requirements:
|
189
190
|
- - ">="
|
190
191
|
- !ruby/object:Gem::Version
|
191
|
-
version: '0'
|
192
|
+
version: '2.0'
|
192
193
|
requirements: []
|
193
|
-
rubygems_version: 3.
|
194
|
-
signing_key:
|
194
|
+
rubygems_version: 3.3.3
|
195
|
+
signing_key:
|
195
196
|
specification_version: 4
|
196
197
|
summary: A utility library for generating HTML strings.
|
197
198
|
test_files: []
|
data/lib/berns/berns.so
DELETED
Binary file
|