selma 0.4.6 → 0.4.7

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: 704b9ef380d21adb07f72fcaf0dda936158514932d9e034f0e5b58ec44ff2e68
4
- data.tar.gz: 3c7155aef5f4be4a08c9fd517f8ea1223431431e95baefa885851a77e1b129bd
3
+ metadata.gz: 04f8ef6623b5a28c62d64f3077842e262321580e998e90ba458735e5d7a13395
4
+ data.tar.gz: 132e7e538f36ad7399fb6edb7c09ece5fb16a9bd94da3a3a18339c0ad4057888
5
5
  SHA512:
6
- metadata.gz: '01719b4c1679e91655fc3b29c8923b2bfcbc64e1633867a11bf53242849b75f5013068feaf59affc5c0cd7aee9d799bc6e4b44fd40eadfe0b301ba7607069fae'
7
- data.tar.gz: 986c81e769ff2aa1a648e1d428c139d9f5dee1e716ca9b67764ca7ec7cba12846bf1fa2df0e22d573263d053e34a0e707bf2bca0f35c4e8ad173a829d6036b5b
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.19"
429
+ version = "0.2.20"
430
430
  source = "registry+https://github.com/rust-lang/crates.io-index"
431
- checksum = "2288c0e17cc8d342c712bb43a257a80ebffce59cdb33d5000d8348f3ec02528b"
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.99"
519
+ version = "0.9.101"
521
520
  source = "registry+https://github.com/rust-lang/crates.io-index"
522
- checksum = "d83151cfea2b67db2444f68c53b119ff77cff235ad711c765072e4daf8f3185b"
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.99"
528
+ version = "0.9.101"
530
529
  source = "registry+https://github.com/rust-lang/crates.io-index"
531
- checksum = "32d038214c118ad4a75db555ccb78672e17e1c5c10f344456cd129008dbaa7de"
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.5"
549
+ version = "1.10.6"
551
550
  source = "registry+https://github.com/rust-lang/crates.io-index"
552
- checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
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
- Ok(text_chunk.as_str().to_string())
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
 
@@ -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
- // seems that sometimes lol-html returns blank text / EOLs?
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Selma
4
- VERSION = "0.4.6"
4
+ VERSION = "0.4.7"
5
5
  end
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.6
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-04 00:00:00.000000000 Z
11
+ date: 2024-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys