selma 0.4.6 → 0.4.7
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/Cargo.lock +8 -9
- data/ext/selma/src/html/text_chunk.rs +32 -2
- data/ext/selma/src/rewriter.rs +2 -1
- data/lib/selma/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: 04f8ef6623b5a28c62d64f3077842e262321580e998e90ba458735e5d7a13395
|
4
|
+
data.tar.gz: 132e7e538f36ad7399fb6edb7c09ece5fb16a9bd94da3a3a18339c0ad4057888
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06a3709aed3c7793b4010174866d4866bedd848cd2e2ca1553dff603e21790c8982d79a0ba72b6c2c5668639da76efd745aff2fbfe496442bbbb5c14cdf0a431
|
7
|
+
data.tar.gz: 86a393c4df2090cdba7f75001ebb81f9262c3f65e9fc897bc5d6fa6a8147e3f37e97118f7787fac22acd86baa241ba3b934e42062df1888e774c768cf3a24729
|
data/Cargo.lock
CHANGED
@@ -426,12 +426,11 @@ dependencies = [
|
|
426
426
|
|
427
427
|
[[package]]
|
428
428
|
name = "ppv-lite86"
|
429
|
-
version = "0.2.
|
429
|
+
version = "0.2.20"
|
430
430
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
431
|
-
checksum = "
|
431
|
+
checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04"
|
432
432
|
dependencies = [
|
433
433
|
"zerocopy",
|
434
|
-
"zerocopy-derive",
|
435
434
|
]
|
436
435
|
|
437
436
|
[[package]]
|
@@ -517,18 +516,18 @@ dependencies = [
|
|
517
516
|
|
518
517
|
[[package]]
|
519
518
|
name = "rb-sys"
|
520
|
-
version = "0.9.
|
519
|
+
version = "0.9.101"
|
521
520
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
522
|
-
checksum = "
|
521
|
+
checksum = "1ba2704ccfa7875c91792c57a9aa7c3caac524d3036c122e36eeddad6f6e7c6f"
|
523
522
|
dependencies = [
|
524
523
|
"rb-sys-build",
|
525
524
|
]
|
526
525
|
|
527
526
|
[[package]]
|
528
527
|
name = "rb-sys-build"
|
529
|
-
version = "0.9.
|
528
|
+
version = "0.9.101"
|
530
529
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
531
|
-
checksum = "
|
530
|
+
checksum = "c73585ec80c217b7a81257ca9bb89b191b5e452ec4b9106dc4c2e4e96a822242"
|
532
531
|
dependencies = [
|
533
532
|
"bindgen",
|
534
533
|
"lazy_static",
|
@@ -547,9 +546,9 @@ checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
|
|
547
546
|
|
548
547
|
[[package]]
|
549
548
|
name = "regex"
|
550
|
-
version = "1.10.
|
549
|
+
version = "1.10.6"
|
551
550
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
552
|
-
checksum = "
|
551
|
+
checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"
|
553
552
|
dependencies = [
|
554
553
|
"aho-corasick",
|
555
554
|
"memchr",
|
@@ -6,6 +6,26 @@ use magnus::{exception, method, Error, Module, RClass, Symbol, Value};
|
|
6
6
|
|
7
7
|
struct HTMLTextChunk {
|
8
8
|
text_chunk: NativeRefWrap<TextChunk<'static>>,
|
9
|
+
buffer: String,
|
10
|
+
}
|
11
|
+
|
12
|
+
macro_rules! clone_buffer_if_not_empty {
|
13
|
+
($binding:expr, $buffer:expr) => {
|
14
|
+
if !$binding.buffer.is_empty() {
|
15
|
+
$buffer.clone_from(&$binding.buffer);
|
16
|
+
}
|
17
|
+
};
|
18
|
+
}
|
19
|
+
|
20
|
+
// if this is the first time we're processing this text chunk (buffer is empty),
|
21
|
+
// we carry on. Otherwise, we need to use the buffer text, not the text chunk,
|
22
|
+
// because lol-html is not designed in such a way to keep track of text chunks.
|
23
|
+
macro_rules! set_text_chunk_to_buffer {
|
24
|
+
($text_chunk:expr, $buffer:expr) => {
|
25
|
+
if !$buffer.is_empty() {
|
26
|
+
$text_chunk.set_str($buffer);
|
27
|
+
}
|
28
|
+
};
|
9
29
|
}
|
10
30
|
|
11
31
|
#[magnus::wrap(class = "Selma::HTML::TextChunk")]
|
@@ -18,6 +38,7 @@ impl SelmaHTMLTextChunk {
|
|
18
38
|
pub fn new(ref_wrap: NativeRefWrap<TextChunk<'static>>) -> Self {
|
19
39
|
Self(RefCell::new(HTMLTextChunk {
|
20
40
|
text_chunk: ref_wrap,
|
41
|
+
buffer: String::new(),
|
21
42
|
}))
|
22
43
|
}
|
23
44
|
|
@@ -96,16 +117,25 @@ impl SelmaHTMLTextChunk {
|
|
96
117
|
|
97
118
|
fn replace(&self, args: &[Value]) -> Result<String, Error> {
|
98
119
|
let mut binding = self.0.borrow_mut();
|
120
|
+
let mut buffer = String::new();
|
121
|
+
|
122
|
+
clone_buffer_if_not_empty!(binding, buffer);
|
123
|
+
|
99
124
|
let text_chunk = binding.text_chunk.get_mut().unwrap();
|
100
125
|
|
126
|
+
set_text_chunk_to_buffer!(text_chunk, buffer);
|
127
|
+
|
101
128
|
let (text_str, content_type) = match crate::scan_text_args(args) {
|
102
129
|
Ok((text_str, content_type)) => (text_str, content_type),
|
103
130
|
Err(err) => return Err(err),
|
104
131
|
};
|
105
|
-
|
106
132
|
text_chunk.replace(&text_str, content_type);
|
107
133
|
|
108
|
-
|
134
|
+
text_chunk.set_str(text_str.clone());
|
135
|
+
|
136
|
+
binding.buffer = text_chunk.as_str().to_string();
|
137
|
+
|
138
|
+
Ok(text_str)
|
109
139
|
}
|
110
140
|
}
|
111
141
|
|
data/ext/selma/src/rewriter.rs
CHANGED
@@ -540,7 +540,8 @@ impl SelmaRewriter {
|
|
540
540
|
// prevents missing `handle_text_chunk` function
|
541
541
|
let content = text_chunk.as_str();
|
542
542
|
|
543
|
-
//
|
543
|
+
// lol-html sometimes returns blank text if
|
544
|
+
// last_in_text_node() is true
|
544
545
|
if content.is_empty() {
|
545
546
|
return Ok(());
|
546
547
|
}
|
data/lib/selma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen J. Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb_sys
|