selma 0.1.6 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +166 -82
- data/Cargo.toml +2 -0
- data/README.md +3 -0
- data/ext/selma/Cargo.toml +4 -2
- data/ext/selma/src/html/element.rs +38 -2
- data/ext/selma/src/html/end_tag.rs +2 -2
- data/ext/selma/src/html/text_chunk.rs +2 -2
- data/ext/selma/src/html.rs +3 -1
- data/ext/selma/src/lib.rs +0 -1
- data/ext/selma/src/rewriter.rs +51 -54
- data/ext/selma/src/sanitizer.rs +17 -22
- data/ext/selma/src/selector.rs +4 -4
- data/ext/selma/src/tags.rs +1 -1
- data/lib/selma/version.rb +1 -1
- metadata +8 -9
- data/ext/selma/src/wrapped_struct.rs +0 -92
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50b438a2bdc8e13515ccc76c7e57a6fffb492c3ac7ff62781226ca5288f22913
|
4
|
+
data.tar.gz: 66b31905df161bf62a2dd88df9a5ead5e9f0a0f3a2d1464b669634dc966bc9a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f37389220da9e5b2ea7193cf1a3b7fa0198351233d5afa871c66679b06f274b161caab8b13222996345008899a5334a37150708533f3fd295ca266a5d1e35d1f
|
7
|
+
data.tar.gz: 2dc168d6bf3d1032fd97dd21f126bfb1028a9b62693b7bc4af254953510f259e96aa7d4c541b23a9a0160c9f5c616b40eebec05b873f0df6fc3d03dc0114f018
|
data/Cargo.lock
CHANGED
@@ -4,31 +4,32 @@ version = 3
|
|
4
4
|
|
5
5
|
[[package]]
|
6
6
|
name = "ahash"
|
7
|
-
version = "0.8.
|
7
|
+
version = "0.8.7"
|
8
8
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
9
|
-
checksum = "
|
9
|
+
checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01"
|
10
10
|
dependencies = [
|
11
11
|
"cfg-if",
|
12
12
|
"once_cell",
|
13
13
|
"version_check",
|
14
|
+
"zerocopy",
|
14
15
|
]
|
15
16
|
|
16
17
|
[[package]]
|
17
18
|
name = "aho-corasick"
|
18
|
-
version = "1.
|
19
|
+
version = "1.1.2"
|
19
20
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
20
|
-
checksum = "
|
21
|
+
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
21
22
|
dependencies = [
|
22
23
|
"memchr",
|
23
24
|
]
|
24
25
|
|
25
26
|
[[package]]
|
26
27
|
name = "bindgen"
|
27
|
-
version = "0.
|
28
|
+
version = "0.69.1"
|
28
29
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
29
|
-
checksum = "
|
30
|
+
checksum = "9ffcebc3849946a7170a05992aac39da343a90676ab392c51a4280981d6379c2"
|
30
31
|
dependencies = [
|
31
|
-
"bitflags
|
32
|
+
"bitflags 2.4.1",
|
32
33
|
"cexpr",
|
33
34
|
"clang-sys",
|
34
35
|
"lazy_static",
|
@@ -39,7 +40,7 @@ dependencies = [
|
|
39
40
|
"regex",
|
40
41
|
"rustc-hash",
|
41
42
|
"shlex",
|
42
|
-
"syn
|
43
|
+
"syn 2.0.46",
|
43
44
|
]
|
44
45
|
|
45
46
|
[[package]]
|
@@ -50,15 +51,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|
50
51
|
|
51
52
|
[[package]]
|
52
53
|
name = "bitflags"
|
53
|
-
version = "2.
|
54
|
+
version = "2.4.1"
|
54
55
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
55
|
-
checksum = "
|
56
|
+
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
|
56
57
|
|
57
58
|
[[package]]
|
58
59
|
name = "byteorder"
|
59
|
-
version = "1.
|
60
|
+
version = "1.5.0"
|
60
61
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
61
|
-
checksum = "
|
62
|
+
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
62
63
|
|
63
64
|
[[package]]
|
64
65
|
name = "cexpr"
|
@@ -77,9 +78,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|
77
78
|
|
78
79
|
[[package]]
|
79
80
|
name = "clang-sys"
|
80
|
-
version = "1.
|
81
|
+
version = "1.7.0"
|
81
82
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
82
|
-
checksum = "
|
83
|
+
checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1"
|
83
84
|
dependencies = [
|
84
85
|
"glob",
|
85
86
|
"libc",
|
@@ -116,7 +117,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
116
117
|
checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331"
|
117
118
|
dependencies = [
|
118
119
|
"quote",
|
119
|
-
"syn 2.0.
|
120
|
+
"syn 2.0.46",
|
120
121
|
]
|
121
122
|
|
122
123
|
[[package]]
|
@@ -134,24 +135,24 @@ dependencies = [
|
|
134
135
|
|
135
136
|
[[package]]
|
136
137
|
name = "dtoa"
|
137
|
-
version = "0.
|
138
|
+
version = "1.0.9"
|
138
139
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
139
|
-
checksum = "
|
140
|
+
checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653"
|
140
141
|
|
141
142
|
[[package]]
|
142
143
|
name = "dtoa-short"
|
143
|
-
version = "0.3.
|
144
|
+
version = "0.3.4"
|
144
145
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
145
|
-
checksum = "
|
146
|
+
checksum = "dbaceec3c6e4211c79e7b1800fb9680527106beb2f9c51904a3210c03a448c74"
|
146
147
|
dependencies = [
|
147
148
|
"dtoa",
|
148
149
|
]
|
149
150
|
|
150
151
|
[[package]]
|
151
152
|
name = "encoding_rs"
|
152
|
-
version = "0.8.
|
153
|
+
version = "0.8.33"
|
153
154
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
154
|
-
checksum = "
|
155
|
+
checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1"
|
155
156
|
dependencies = [
|
156
157
|
"cfg-if",
|
157
158
|
]
|
@@ -179,7 +180,7 @@ checksum = "eecf8589574ce9b895052fa12d69af7a233f99e6107f5cb8dd1044f2a17bfdcb"
|
|
179
180
|
dependencies = [
|
180
181
|
"proc-macro2",
|
181
182
|
"quote",
|
182
|
-
"syn 2.0.
|
183
|
+
"syn 2.0.46",
|
183
184
|
]
|
184
185
|
|
185
186
|
[[package]]
|
@@ -246,33 +247,33 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
|
246
247
|
|
247
248
|
[[package]]
|
248
249
|
name = "libc"
|
249
|
-
version = "0.2.
|
250
|
+
version = "0.2.151"
|
250
251
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
251
|
-
checksum = "
|
252
|
+
checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
|
252
253
|
|
253
254
|
[[package]]
|
254
255
|
name = "libloading"
|
255
|
-
version = "0.
|
256
|
+
version = "0.8.1"
|
256
257
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
257
|
-
checksum = "
|
258
|
+
checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161"
|
258
259
|
dependencies = [
|
259
260
|
"cfg-if",
|
260
|
-
"
|
261
|
+
"windows-sys",
|
261
262
|
]
|
262
263
|
|
263
264
|
[[package]]
|
264
265
|
name = "log"
|
265
|
-
version = "0.4.
|
266
|
+
version = "0.4.20"
|
266
267
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
267
|
-
checksum = "
|
268
|
+
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
268
269
|
|
269
270
|
[[package]]
|
270
271
|
name = "lol_html"
|
271
|
-
version = "1.
|
272
|
+
version = "1.2.0"
|
272
273
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
273
|
-
checksum = "
|
274
|
+
checksum = "10662f7aad081ec900fd735be33076da75e0389400277dc3734e2b0aa02bb115"
|
274
275
|
dependencies = [
|
275
|
-
"bitflags 2.
|
276
|
+
"bitflags 2.4.1",
|
276
277
|
"cfg-if",
|
277
278
|
"cssparser",
|
278
279
|
"encoding_rs",
|
@@ -288,24 +289,25 @@ dependencies = [
|
|
288
289
|
|
289
290
|
[[package]]
|
290
291
|
name = "magnus"
|
291
|
-
version = "0.
|
292
|
+
version = "0.6.2"
|
292
293
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
293
|
-
checksum = "
|
294
|
+
checksum = "4778544796676e8428e9c622460ebf284bea52d8b10db3aeb449d8b5e61b3a13"
|
294
295
|
dependencies = [
|
295
296
|
"magnus-macros",
|
296
297
|
"rb-sys",
|
297
298
|
"rb-sys-env",
|
299
|
+
"seq-macro",
|
298
300
|
]
|
299
301
|
|
300
302
|
[[package]]
|
301
303
|
name = "magnus-macros"
|
302
|
-
version = "0.
|
304
|
+
version = "0.6.0"
|
303
305
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
304
|
-
checksum = "
|
306
|
+
checksum = "5968c820e2960565f647819f5928a42d6e874551cab9d88d75e3e0660d7f71e3"
|
305
307
|
dependencies = [
|
306
308
|
"proc-macro2",
|
307
309
|
"quote",
|
308
|
-
"syn
|
310
|
+
"syn 2.0.46",
|
309
311
|
]
|
310
312
|
|
311
313
|
[[package]]
|
@@ -316,9 +318,9 @@ checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
|
|
316
318
|
|
317
319
|
[[package]]
|
318
320
|
name = "memchr"
|
319
|
-
version = "2.
|
321
|
+
version = "2.7.1"
|
320
322
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
321
|
-
checksum = "
|
323
|
+
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
|
322
324
|
|
323
325
|
[[package]]
|
324
326
|
name = "mime"
|
@@ -350,9 +352,9 @@ dependencies = [
|
|
350
352
|
|
351
353
|
[[package]]
|
352
354
|
name = "once_cell"
|
353
|
-
version = "1.
|
355
|
+
version = "1.19.0"
|
354
356
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
355
|
-
checksum = "
|
357
|
+
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
356
358
|
|
357
359
|
[[package]]
|
358
360
|
name = "peeking_take_while"
|
@@ -434,18 +436,18 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
|
|
434
436
|
|
435
437
|
[[package]]
|
436
438
|
name = "proc-macro2"
|
437
|
-
version = "1.0.
|
439
|
+
version = "1.0.74"
|
438
440
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
439
|
-
checksum = "
|
441
|
+
checksum = "2de98502f212cfcea8d0bb305bd0f49d7ebdd75b64ba0a68f937d888f4e0d6db"
|
440
442
|
dependencies = [
|
441
443
|
"unicode-ident",
|
442
444
|
]
|
443
445
|
|
444
446
|
[[package]]
|
445
447
|
name = "quote"
|
446
|
-
version = "1.0.
|
448
|
+
version = "1.0.35"
|
447
449
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
448
|
-
checksum = "
|
450
|
+
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
449
451
|
dependencies = [
|
450
452
|
"proc-macro2",
|
451
453
|
]
|
@@ -503,18 +505,18 @@ dependencies = [
|
|
503
505
|
|
504
506
|
[[package]]
|
505
507
|
name = "rb-sys"
|
506
|
-
version = "0.9.
|
508
|
+
version = "0.9.85"
|
507
509
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
508
|
-
checksum = "
|
510
|
+
checksum = "05b780e6858b0b0eced1d55d0f097c024b77a37b41f83bd35341130f78e37c51"
|
509
511
|
dependencies = [
|
510
512
|
"rb-sys-build",
|
511
513
|
]
|
512
514
|
|
513
515
|
[[package]]
|
514
516
|
name = "rb-sys-build"
|
515
|
-
version = "0.9.
|
517
|
+
version = "0.9.85"
|
516
518
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
517
|
-
checksum = "
|
519
|
+
checksum = "44957a3bc513dad1b0f20bdd0ee3b82e729a59da44086a6b40d8bc71958a6db8"
|
518
520
|
dependencies = [
|
519
521
|
"bindgen",
|
520
522
|
"lazy_static",
|
@@ -522,7 +524,7 @@ dependencies = [
|
|
522
524
|
"quote",
|
523
525
|
"regex",
|
524
526
|
"shell-words",
|
525
|
-
"syn
|
527
|
+
"syn 2.0.46",
|
526
528
|
]
|
527
529
|
|
528
530
|
[[package]]
|
@@ -533,9 +535,21 @@ checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
|
|
533
535
|
|
534
536
|
[[package]]
|
535
537
|
name = "regex"
|
536
|
-
version = "1.
|
538
|
+
version = "1.10.2"
|
537
539
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
538
|
-
checksum = "
|
540
|
+
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
|
541
|
+
dependencies = [
|
542
|
+
"aho-corasick",
|
543
|
+
"memchr",
|
544
|
+
"regex-automata",
|
545
|
+
"regex-syntax",
|
546
|
+
]
|
547
|
+
|
548
|
+
[[package]]
|
549
|
+
name = "regex-automata"
|
550
|
+
version = "0.4.3"
|
551
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
552
|
+
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
|
539
553
|
dependencies = [
|
540
554
|
"aho-corasick",
|
541
555
|
"memchr",
|
@@ -544,9 +558,9 @@ dependencies = [
|
|
544
558
|
|
545
559
|
[[package]]
|
546
560
|
name = "regex-syntax"
|
547
|
-
version = "0.
|
561
|
+
version = "0.8.2"
|
548
562
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
549
|
-
checksum = "
|
563
|
+
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
550
564
|
|
551
565
|
[[package]]
|
552
566
|
name = "rustc-hash"
|
@@ -601,9 +615,15 @@ dependencies = [
|
|
601
615
|
|
602
616
|
[[package]]
|
603
617
|
name = "semver"
|
604
|
-
version = "1.0.
|
618
|
+
version = "1.0.21"
|
605
619
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
606
|
-
checksum = "
|
620
|
+
checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0"
|
621
|
+
|
622
|
+
[[package]]
|
623
|
+
name = "seq-macro"
|
624
|
+
version = "0.3.5"
|
625
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
626
|
+
checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4"
|
607
627
|
|
608
628
|
[[package]]
|
609
629
|
name = "servo_arc"
|
@@ -623,21 +643,21 @@ checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
|
|
623
643
|
|
624
644
|
[[package]]
|
625
645
|
name = "shlex"
|
626
|
-
version = "1.
|
646
|
+
version = "1.2.0"
|
627
647
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
628
|
-
checksum = "
|
648
|
+
checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380"
|
629
649
|
|
630
650
|
[[package]]
|
631
651
|
name = "siphasher"
|
632
|
-
version = "0.3.
|
652
|
+
version = "0.3.11"
|
633
653
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
634
|
-
checksum = "
|
654
|
+
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
|
635
655
|
|
636
656
|
[[package]]
|
637
657
|
name = "smallvec"
|
638
|
-
version = "1.
|
658
|
+
version = "1.11.2"
|
639
659
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
640
|
-
checksum = "
|
660
|
+
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
|
641
661
|
|
642
662
|
[[package]]
|
643
663
|
name = "stable_deref_trait"
|
@@ -658,9 +678,9 @@ dependencies = [
|
|
658
678
|
|
659
679
|
[[package]]
|
660
680
|
name = "syn"
|
661
|
-
version = "2.0.
|
681
|
+
version = "2.0.46"
|
662
682
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
663
|
-
checksum = "
|
683
|
+
checksum = "89456b690ff72fddcecf231caedbe615c59480c93358a93dfae7fc29e3ebbf0e"
|
664
684
|
dependencies = [
|
665
685
|
"proc-macro2",
|
666
686
|
"quote",
|
@@ -675,29 +695,29 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c"
|
|
675
695
|
|
676
696
|
[[package]]
|
677
697
|
name = "thiserror"
|
678
|
-
version = "1.0.
|
698
|
+
version = "1.0.56"
|
679
699
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
680
|
-
checksum = "
|
700
|
+
checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"
|
681
701
|
dependencies = [
|
682
702
|
"thiserror-impl",
|
683
703
|
]
|
684
704
|
|
685
705
|
[[package]]
|
686
706
|
name = "thiserror-impl"
|
687
|
-
version = "1.0.
|
707
|
+
version = "1.0.56"
|
688
708
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
689
|
-
checksum = "
|
709
|
+
checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
|
690
710
|
dependencies = [
|
691
711
|
"proc-macro2",
|
692
712
|
"quote",
|
693
|
-
"syn 2.0.
|
713
|
+
"syn 2.0.46",
|
694
714
|
]
|
695
715
|
|
696
716
|
[[package]]
|
697
717
|
name = "unicode-ident"
|
698
|
-
version = "1.0.
|
718
|
+
version = "1.0.12"
|
699
719
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
700
|
-
checksum = "
|
720
|
+
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
701
721
|
|
702
722
|
[[package]]
|
703
723
|
name = "version_check"
|
@@ -712,23 +732,87 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
712
732
|
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
713
733
|
|
714
734
|
[[package]]
|
715
|
-
name = "
|
716
|
-
version = "0.
|
735
|
+
name = "windows-sys"
|
736
|
+
version = "0.48.0"
|
717
737
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
718
|
-
checksum = "
|
738
|
+
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
719
739
|
dependencies = [
|
720
|
-
"
|
721
|
-
"winapi-x86_64-pc-windows-gnu",
|
740
|
+
"windows-targets",
|
722
741
|
]
|
723
742
|
|
724
743
|
[[package]]
|
725
|
-
name = "
|
726
|
-
version = "0.
|
744
|
+
name = "windows-targets"
|
745
|
+
version = "0.48.5"
|
727
746
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
728
|
-
checksum = "
|
747
|
+
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
748
|
+
dependencies = [
|
749
|
+
"windows_aarch64_gnullvm",
|
750
|
+
"windows_aarch64_msvc",
|
751
|
+
"windows_i686_gnu",
|
752
|
+
"windows_i686_msvc",
|
753
|
+
"windows_x86_64_gnu",
|
754
|
+
"windows_x86_64_gnullvm",
|
755
|
+
"windows_x86_64_msvc",
|
756
|
+
]
|
729
757
|
|
730
758
|
[[package]]
|
731
|
-
name = "
|
732
|
-
version = "0.
|
759
|
+
name = "windows_aarch64_gnullvm"
|
760
|
+
version = "0.48.5"
|
761
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
762
|
+
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
763
|
+
|
764
|
+
[[package]]
|
765
|
+
name = "windows_aarch64_msvc"
|
766
|
+
version = "0.48.5"
|
767
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
768
|
+
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
769
|
+
|
770
|
+
[[package]]
|
771
|
+
name = "windows_i686_gnu"
|
772
|
+
version = "0.48.5"
|
773
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
774
|
+
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
775
|
+
|
776
|
+
[[package]]
|
777
|
+
name = "windows_i686_msvc"
|
778
|
+
version = "0.48.5"
|
733
779
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
734
|
-
checksum = "
|
780
|
+
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
781
|
+
|
782
|
+
[[package]]
|
783
|
+
name = "windows_x86_64_gnu"
|
784
|
+
version = "0.48.5"
|
785
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
786
|
+
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
787
|
+
|
788
|
+
[[package]]
|
789
|
+
name = "windows_x86_64_gnullvm"
|
790
|
+
version = "0.48.5"
|
791
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
792
|
+
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
793
|
+
|
794
|
+
[[package]]
|
795
|
+
name = "windows_x86_64_msvc"
|
796
|
+
version = "0.48.5"
|
797
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
798
|
+
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
799
|
+
|
800
|
+
[[package]]
|
801
|
+
name = "zerocopy"
|
802
|
+
version = "0.7.32"
|
803
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
804
|
+
checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
|
805
|
+
dependencies = [
|
806
|
+
"zerocopy-derive",
|
807
|
+
]
|
808
|
+
|
809
|
+
[[package]]
|
810
|
+
name = "zerocopy-derive"
|
811
|
+
version = "0.7.32"
|
812
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
813
|
+
checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
|
814
|
+
dependencies = [
|
815
|
+
"proc-macro2",
|
816
|
+
"quote",
|
817
|
+
"syn 2.0.46",
|
818
|
+
]
|
data/Cargo.toml
CHANGED
data/README.md
CHANGED
@@ -164,6 +164,9 @@ The `element` argument in `handle_element` has the following methods:
|
|
164
164
|
- `prepend(content, as: content_type)`: prepends `content` to the element's inner content, i.e. inserts content right after the element's start tag. `content_type` is either `:text` or `:html` and determines how the content will be applied.
|
165
165
|
- `append(content, as: content_type)`: appends `content` to the element's inner content, i.e. inserts content right before the element's end tag. `content_type` is either `:text` or `:html` and determines how the content will be applied.
|
166
166
|
- `set_inner_content`: Replaces inner content of the element with `content`. `content_type` is either `:text` or `:html` and determines how the content will be applied.
|
167
|
+
- `remove`: Removes the element and its inner content.
|
168
|
+
- `remove_and_keep_content`: Removes the element, but keeps its content. I.e. remove start and end tags of the element.
|
169
|
+
- `removed?`: A bool which identifies if the element has been removed or replaced with some content.
|
167
170
|
|
168
171
|
#### `text_chunk` methods
|
169
172
|
|
data/ext/selma/Cargo.toml
CHANGED
@@ -2,12 +2,14 @@
|
|
2
2
|
name = "selma"
|
3
3
|
version = "1.0.0"
|
4
4
|
edition = "2021"
|
5
|
+
rust-version = "1.75.0"
|
6
|
+
publish = false
|
5
7
|
|
6
8
|
[dependencies]
|
7
9
|
enum-iterator = "1.4"
|
8
10
|
escapist = "0.0.2"
|
9
|
-
magnus = "0.
|
10
|
-
lol_html = "1.
|
11
|
+
magnus = "0.6"
|
12
|
+
lol_html = "1.2"
|
11
13
|
|
12
14
|
[lib]
|
13
15
|
name = "selma"
|
@@ -215,12 +215,41 @@ impl SelmaHTMLElement {
|
|
215
215
|
|
216
216
|
Ok(())
|
217
217
|
}
|
218
|
+
|
219
|
+
fn remove(&self) {
|
220
|
+
let mut binding = self.0.borrow_mut();
|
221
|
+
|
222
|
+
if let Ok(e) = binding.element.get_mut() {
|
223
|
+
e.remove()
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
fn remove_and_keep_content(&self) {
|
228
|
+
let mut binding = self.0.borrow_mut();
|
229
|
+
|
230
|
+
if let Ok(e) = binding.element.get_mut() {
|
231
|
+
e.remove_and_keep_content()
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
fn is_removed(&self) -> Result<bool, Error> {
|
236
|
+
let binding = self.0.borrow();
|
237
|
+
|
238
|
+
if let Ok(e) = binding.element.get() {
|
239
|
+
Ok(e.removed())
|
240
|
+
} else {
|
241
|
+
Err(Error::new(
|
242
|
+
exception::runtime_error(),
|
243
|
+
"`is_removed` is not available",
|
244
|
+
))
|
245
|
+
}
|
246
|
+
}
|
218
247
|
}
|
219
248
|
|
220
249
|
pub fn init(c_html: RClass) -> Result<(), Error> {
|
221
250
|
let c_element = c_html
|
222
|
-
.define_class("Element",
|
223
|
-
.expect("cannot
|
251
|
+
.define_class("Element", magnus::class::object())
|
252
|
+
.expect("cannot define class Selma::HTML::Element");
|
224
253
|
|
225
254
|
c_element.define_method("tag_name", method!(SelmaHTMLElement::tag_name, 0))?;
|
226
255
|
c_element.define_method("tag_name=", method!(SelmaHTMLElement::set_tag_name, 1))?;
|
@@ -250,5 +279,12 @@ pub fn init(c_html: RClass) -> Result<(), Error> {
|
|
250
279
|
method!(SelmaHTMLElement::set_inner_content, -1),
|
251
280
|
)?;
|
252
281
|
|
282
|
+
c_element.define_method("remove", method!(SelmaHTMLElement::remove, 0))?;
|
283
|
+
c_element.define_method(
|
284
|
+
"remove_and_keep_content",
|
285
|
+
method!(SelmaHTMLElement::remove_and_keep_content, 0),
|
286
|
+
)?;
|
287
|
+
c_element.define_method("removed?", method!(SelmaHTMLElement::is_removed, 0))?;
|
288
|
+
|
253
289
|
Ok(())
|
254
290
|
}
|
@@ -26,8 +26,8 @@ impl SelmaHTMLEndTag {
|
|
26
26
|
|
27
27
|
pub fn init(c_html: RClass) -> Result<(), Error> {
|
28
28
|
let c_end_tag = c_html
|
29
|
-
.define_class("EndTag",
|
30
|
-
.expect("cannot
|
29
|
+
.define_class("EndTag", magnus::class::object())
|
30
|
+
.expect("cannot define class Selma::HTML::EndTag");
|
31
31
|
|
32
32
|
c_end_tag.define_method("tag_name", method!(SelmaHTMLEndTag::tag_name, 0))?;
|
33
33
|
|
@@ -99,8 +99,8 @@ impl SelmaHTMLTextChunk {
|
|
99
99
|
|
100
100
|
pub fn init(c_html: RClass) -> Result<(), Error> {
|
101
101
|
let c_text_chunk = c_html
|
102
|
-
.define_class("TextChunk",
|
103
|
-
.expect("cannot
|
102
|
+
.define_class("TextChunk", magnus::class::object())
|
103
|
+
.expect("cannot define class Selma::HTML::TextChunk");
|
104
104
|
|
105
105
|
c_text_chunk.define_method("to_s", method!(SelmaHTMLTextChunk::to_s, 0))?;
|
106
106
|
c_text_chunk.define_method("content", method!(SelmaHTMLTextChunk::to_s, 0))?;
|
data/ext/selma/src/html.rs
CHANGED
@@ -5,7 +5,9 @@ use magnus::{Error, Module, RModule};
|
|
5
5
|
pub(crate) struct SelmaHTML {}
|
6
6
|
|
7
7
|
pub fn init(m_selma: RModule) -> Result<(), Error> {
|
8
|
-
let c_html = m_selma
|
8
|
+
let c_html = m_selma
|
9
|
+
.define_class("HTML", magnus::class::object())
|
10
|
+
.expect("cannot define class Selma::HTML");
|
9
11
|
|
10
12
|
element::init(c_html).expect("cannot define Selma::HTML::Element class");
|
11
13
|
end_tag::init(c_html).expect("cannot define Selma::HTML::EndTag class");
|
data/ext/selma/src/lib.rs
CHANGED
data/ext/selma/src/rewriter.rs
CHANGED
@@ -3,7 +3,12 @@ use lol_html::{
|
|
3
3
|
html_content::{Element, TextChunk},
|
4
4
|
text, DocumentContentHandlers, ElementContentHandlers, HtmlRewriter, Selector, Settings,
|
5
5
|
};
|
6
|
-
use magnus::{
|
6
|
+
use magnus::{
|
7
|
+
exception, function, method, scan_args,
|
8
|
+
typed_data::Obj,
|
9
|
+
value::{Opaque, ReprValue},
|
10
|
+
Module, Object, RArray, RModule, Ruby, Value,
|
11
|
+
};
|
7
12
|
|
8
13
|
use std::{borrow::Cow, cell::RefCell, primitive::str, rc::Rc};
|
9
14
|
|
@@ -12,35 +17,34 @@ use crate::{
|
|
12
17
|
sanitizer::SelmaSanitizer,
|
13
18
|
selector::SelmaSelector,
|
14
19
|
tags::Tag,
|
15
|
-
wrapped_struct::WrappedStruct,
|
16
20
|
};
|
17
21
|
|
18
|
-
#[derive(Clone
|
22
|
+
#[derive(Clone)]
|
19
23
|
pub struct Handler {
|
20
|
-
rb_handler: Value
|
21
|
-
rb_selector:
|
22
|
-
|
23
|
-
|
24
|
-
total_elapsed_element_handlers: f64,
|
24
|
+
rb_handler: Opaque<Value>,
|
25
|
+
rb_selector: Opaque<Obj<SelmaSelector>>,
|
26
|
+
// total_element_handler_calls: usize,
|
27
|
+
// total_elapsed_element_handlers: f64,
|
25
28
|
|
26
|
-
total_text_handler_calls: usize,
|
27
|
-
total_elapsed_text_handlers: f64,
|
29
|
+
// total_text_handler_calls: usize,
|
30
|
+
// total_elapsed_text_handlers: f64,
|
28
31
|
}
|
29
32
|
|
30
33
|
pub struct Rewriter {
|
31
34
|
sanitizer: Option<SelmaSanitizer>,
|
32
35
|
handlers: Vec<Handler>,
|
33
|
-
|
34
|
-
total_elapsed: f64,
|
36
|
+
// total_elapsed: f64,
|
35
37
|
}
|
36
38
|
|
37
39
|
#[magnus::wrap(class = "Selma::Rewriter")]
|
38
40
|
pub struct SelmaRewriter(std::cell::RefCell<Rewriter>);
|
39
41
|
|
42
|
+
type RewriterValues = (Option<Option<Obj<SelmaSanitizer>>>, Option<RArray>);
|
43
|
+
|
40
44
|
impl SelmaRewriter {
|
41
|
-
const SELMA_ON_END_TAG: &str = "on_end_tag";
|
42
|
-
const SELMA_HANDLE_ELEMENT: &str = "handle_element";
|
43
|
-
const SELMA_HANDLE_TEXT_CHUNK: &str = "handle_text_chunk";
|
45
|
+
const SELMA_ON_END_TAG: &'static str = "on_end_tag";
|
46
|
+
const SELMA_HANDLE_ELEMENT: &'static str = "handle_element";
|
47
|
+
const SELMA_HANDLE_TEXT_CHUNK: &'static str = "handle_text_chunk";
|
44
48
|
|
45
49
|
/// @yard
|
46
50
|
/// @def new(sanitizer: Selma::Sanitizer.new(Selma::Sanitizer::Config::DEFAULT), handlers: [])
|
@@ -52,16 +56,17 @@ impl SelmaRewriter {
|
|
52
56
|
|
53
57
|
let sanitizer = match rb_sanitizer {
|
54
58
|
None => {
|
59
|
+
// no `sanitizer:` provided, use default
|
55
60
|
let default_sanitizer = SelmaSanitizer::new(&[])?;
|
56
|
-
let wrapped_sanitizer =
|
61
|
+
let wrapped_sanitizer = Obj::wrap(default_sanitizer);
|
57
62
|
wrapped_sanitizer.funcall::<&str, (), Value>("setup", ())?;
|
58
|
-
Some(wrapped_sanitizer.get().
|
63
|
+
Some(wrapped_sanitizer.get().to_owned())
|
59
64
|
}
|
60
65
|
Some(sanitizer_value) => match sanitizer_value {
|
61
|
-
None => None,
|
66
|
+
None => None, // no `sanitizer:` provided, use default
|
62
67
|
Some(sanitizer) => {
|
63
68
|
sanitizer.funcall::<&str, (), Value>("setup", ())?;
|
64
|
-
Some(sanitizer.get().
|
69
|
+
Some(sanitizer.get().to_owned())
|
65
70
|
}
|
66
71
|
},
|
67
72
|
};
|
@@ -86,24 +91,23 @@ impl SelmaRewriter {
|
|
86
91
|
));
|
87
92
|
}
|
88
93
|
|
89
|
-
let rb_selector:
|
90
|
-
|
91
|
-
Err(
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
};
|
94
|
+
let rb_selector: Obj<SelmaSelector> = match rb_handler.funcall("selector", ()) {
|
95
|
+
Err(err) => {
|
96
|
+
return Err(magnus::Error::new(
|
97
|
+
exception::type_error(),
|
98
|
+
format!("Error instantiating selector: {err:?}"),
|
99
|
+
));
|
100
|
+
}
|
101
|
+
Ok(rb_selector) => rb_selector,
|
102
|
+
};
|
99
103
|
let handler = Handler {
|
100
|
-
rb_handler,
|
101
|
-
rb_selector,
|
102
|
-
total_element_handler_calls: 0,
|
103
|
-
total_elapsed_element_handlers: 0.0,
|
104
|
+
rb_handler: Opaque::from(rb_handler),
|
105
|
+
rb_selector: Opaque::from(rb_selector),
|
106
|
+
// total_element_handler_calls: 0,
|
107
|
+
// total_elapsed_element_handlers: 0.0,
|
104
108
|
|
105
|
-
total_text_handler_calls: 0,
|
106
|
-
total_elapsed_text_handlers: 0.0,
|
109
|
+
// total_text_handler_calls: 0,
|
110
|
+
// total_elapsed_text_handlers: 0.0,
|
107
111
|
};
|
108
112
|
handlers.push(handler);
|
109
113
|
}
|
@@ -121,20 +125,12 @@ impl SelmaRewriter {
|
|
121
125
|
Ok(Self(std::cell::RefCell::new(Rewriter {
|
122
126
|
sanitizer,
|
123
127
|
handlers,
|
124
|
-
total_elapsed: 0.0,
|
128
|
+
// total_elapsed: 0.0,
|
125
129
|
})))
|
126
130
|
}
|
127
131
|
|
128
132
|
#[allow(clippy::let_unit_value)]
|
129
|
-
fn scan_parse_args(
|
130
|
-
args: &[Value],
|
131
|
-
) -> Result<
|
132
|
-
(
|
133
|
-
Option<Option<WrappedStruct<SelmaSanitizer>>>,
|
134
|
-
Option<RArray>,
|
135
|
-
),
|
136
|
-
magnus::Error,
|
137
|
-
> {
|
133
|
+
fn scan_parse_args(args: &[Value]) -> Result<RewriterValues, magnus::Error> {
|
138
134
|
let args = scan_args::scan_args(args)?;
|
139
135
|
let _: () = args.required;
|
140
136
|
let _: () = args.optional;
|
@@ -145,10 +141,7 @@ impl SelmaRewriter {
|
|
145
141
|
let kwargs = scan_args::get_kwargs::<
|
146
142
|
_,
|
147
143
|
(),
|
148
|
-
(
|
149
|
-
Option<Option<WrappedStruct<SelmaSanitizer>>>,
|
150
|
-
Option<RArray>,
|
151
|
-
),
|
144
|
+
(Option<Option<Obj<SelmaSanitizer>>>, Option<RArray>),
|
152
145
|
(),
|
153
146
|
>(args.keywords, &[], &["sanitizer", "handlers"])?;
|
154
147
|
let (rb_sanitizer, rb_handlers) = kwargs.optional;
|
@@ -270,7 +263,9 @@ impl SelmaRewriter {
|
|
270
263
|
handlers.iter().for_each(|handler| {
|
271
264
|
let element_stack: Rc<RefCell<Vec<String>>> = Rc::new(RefCell::new(vec![]));
|
272
265
|
|
273
|
-
let
|
266
|
+
let ruby = Ruby::get().unwrap();
|
267
|
+
|
268
|
+
let selector = ruby.get_inner(handler.rb_selector);
|
274
269
|
|
275
270
|
// TODO: test final raise by simulating errors
|
276
271
|
if selector.match_element().is_some() {
|
@@ -280,7 +275,7 @@ impl SelmaRewriter {
|
|
280
275
|
selector.match_element().unwrap(),
|
281
276
|
move |el| {
|
282
277
|
match Self::process_element_handlers(
|
283
|
-
handler.rb_handler,
|
278
|
+
ruby.get_inner(handler.rb_handler),
|
284
279
|
el,
|
285
280
|
&closure_element_stack.borrow(),
|
286
281
|
) {
|
@@ -311,7 +306,9 @@ impl SelmaRewriter {
|
|
311
306
|
}
|
312
307
|
}
|
313
308
|
|
314
|
-
|
309
|
+
let ruby = Ruby::get().unwrap();
|
310
|
+
match Self::process_text_handlers(ruby.get_inner(handler.rb_handler), text)
|
311
|
+
{
|
315
312
|
Ok(_) => Ok(()),
|
316
313
|
Err(err) => Err(err.to_string().into()),
|
317
314
|
}
|
@@ -421,8 +418,8 @@ impl SelmaRewriter {
|
|
421
418
|
|
422
419
|
pub fn init(m_selma: RModule) -> Result<(), magnus::Error> {
|
423
420
|
let c_rewriter = m_selma
|
424
|
-
.define_class("Rewriter",
|
425
|
-
.expect("cannot
|
421
|
+
.define_class("Rewriter", magnus::class::object())
|
422
|
+
.expect("cannot define class Selma::Rewriter");
|
426
423
|
|
427
424
|
c_rewriter.define_singleton_method("new", function!(SelmaRewriter::new, -1))?;
|
428
425
|
c_rewriter
|
data/ext/selma/src/sanitizer.rs
CHANGED
@@ -4,9 +4,13 @@ use lol_html::{
|
|
4
4
|
errors::AttributeNameError,
|
5
5
|
html_content::{Comment, ContentType, Doctype, Element, EndTag},
|
6
6
|
};
|
7
|
-
use magnus::{
|
7
|
+
use magnus::{
|
8
|
+
class, function, method, scan_args,
|
9
|
+
value::{Opaque, ReprValue},
|
10
|
+
Module, Object, RArray, RHash, RModule, Ruby, Value,
|
11
|
+
};
|
8
12
|
|
9
|
-
#[derive(Clone, Debug)]
|
13
|
+
#[derive(Clone, Debug, Default)]
|
10
14
|
struct ElementSanitizer {
|
11
15
|
allowed_attrs: Vec<String>,
|
12
16
|
required_attrs: Vec<String>,
|
@@ -14,19 +18,7 @@ struct ElementSanitizer {
|
|
14
18
|
protocol_sanitizers: HashMap<String, Vec<String>>,
|
15
19
|
}
|
16
20
|
|
17
|
-
|
18
|
-
fn default() -> Self {
|
19
|
-
ElementSanitizer {
|
20
|
-
allowed_attrs: vec![],
|
21
|
-
allowed_classes: vec![],
|
22
|
-
required_attrs: vec![],
|
23
|
-
|
24
|
-
protocol_sanitizers: HashMap::new(),
|
25
|
-
}
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
#[derive(Clone, Debug)]
|
21
|
+
#[derive(Clone)]
|
30
22
|
pub struct Sanitizer {
|
31
23
|
flags: [u8; crate::tags::Tag::TAG_COUNT],
|
32
24
|
allowed_attrs: Vec<String>,
|
@@ -36,10 +28,10 @@ pub struct Sanitizer {
|
|
36
28
|
pub escape_tagfilter: bool,
|
37
29
|
pub allow_comments: bool,
|
38
30
|
pub allow_doctype: bool,
|
39
|
-
config: RHash
|
31
|
+
config: Opaque<RHash>,
|
40
32
|
}
|
41
33
|
|
42
|
-
#[derive(Clone
|
34
|
+
#[derive(Clone)]
|
43
35
|
#[magnus::wrap(class = "Selma::Sanitizer")]
|
44
36
|
pub struct SelmaSanitizer(std::cell::RefCell<Sanitizer>);
|
45
37
|
|
@@ -77,14 +69,15 @@ impl SelmaSanitizer {
|
|
77
69
|
escape_tagfilter: true,
|
78
70
|
allow_comments: false,
|
79
71
|
allow_doctype: true,
|
80
|
-
config,
|
72
|
+
config: config.into(),
|
81
73
|
})))
|
82
74
|
}
|
83
75
|
|
84
76
|
fn get_config(&self) -> Result<RHash, magnus::Error> {
|
85
77
|
let binding = self.0.borrow();
|
78
|
+
let ruby = Ruby::get().unwrap();
|
86
79
|
|
87
|
-
Ok(binding.config)
|
80
|
+
Ok(ruby.get_inner(binding.config))
|
88
81
|
}
|
89
82
|
|
90
83
|
/// Toggle a sanitizer option on or off.
|
@@ -308,9 +301,9 @@ impl SelmaSanitizer {
|
|
308
301
|
let mut buf = String::new();
|
309
302
|
// ...then, escape any special characters, for security
|
310
303
|
if attr_name == "href" {
|
311
|
-
escapist::escape_href(&mut buf, unescaped_attr_val.as_str());
|
304
|
+
escapist::escape_href(&mut buf, unescaped_attr_val.as_str()).unwrap();
|
312
305
|
} else {
|
313
|
-
escapist::escape_html(&mut buf, unescaped_attr_val.as_str());
|
306
|
+
escapist::escape_html(&mut buf, unescaped_attr_val.as_str()).unwrap();
|
314
307
|
};
|
315
308
|
|
316
309
|
match element.set_attribute(attr_name, &buf) {
|
@@ -554,7 +547,9 @@ impl SelmaSanitizer {
|
|
554
547
|
}
|
555
548
|
|
556
549
|
pub fn init(m_selma: RModule) -> Result<(), magnus::Error> {
|
557
|
-
let c_sanitizer = m_selma
|
550
|
+
let c_sanitizer = m_selma
|
551
|
+
.define_class("Sanitizer", magnus::class::object())
|
552
|
+
.expect("cannot define class Selma::Sanitizer");
|
558
553
|
|
559
554
|
c_sanitizer.define_singleton_method("new", function!(SelmaSanitizer::new, -1))?;
|
560
555
|
c_sanitizer.define_method("config", method!(SelmaSanitizer::get_config, 0))?;
|
data/ext/selma/src/selector.rs
CHANGED
@@ -8,6 +8,8 @@ pub struct SelmaSelector {
|
|
8
8
|
ignore_text_within: Option<Vec<String>>,
|
9
9
|
}
|
10
10
|
|
11
|
+
type SelectorMatches = (Option<String>, Option<String>, Option<Vec<String>>);
|
12
|
+
|
11
13
|
impl SelmaSelector {
|
12
14
|
fn new(args: &[Value]) -> Result<Self, Error> {
|
13
15
|
let (match_element, match_text_within, rb_ignore_text_within) =
|
@@ -63,9 +65,7 @@ impl SelmaSelector {
|
|
63
65
|
}
|
64
66
|
|
65
67
|
#[allow(clippy::let_unit_value)]
|
66
|
-
fn scan_parse_args(
|
67
|
-
args: &[Value],
|
68
|
-
) -> Result<(Option<String>, Option<String>, Option<Vec<String>>), Error> {
|
68
|
+
fn scan_parse_args(args: &[Value]) -> Result<SelectorMatches, Error> {
|
69
69
|
let args = scan_args::scan_args(args)?;
|
70
70
|
let _: () = args.required;
|
71
71
|
let _: () = args.optional;
|
@@ -103,7 +103,7 @@ impl SelmaSelector {
|
|
103
103
|
|
104
104
|
pub fn init(m_selma: RModule) -> Result<(), Error> {
|
105
105
|
let c_selector = m_selma
|
106
|
-
.define_class("Selector",
|
106
|
+
.define_class("Selector", magnus::class::object())
|
107
107
|
.expect("cannot define class Selma::Selector");
|
108
108
|
|
109
109
|
c_selector.define_singleton_method("new", function!(SelmaSelector::new, -1))?;
|
data/ext/selma/src/tags.rs
CHANGED
@@ -205,7 +205,7 @@ impl Tag {
|
|
205
205
|
|| tag.index == HTMLTag::XMP as usize
|
206
206
|
}
|
207
207
|
|
208
|
-
pub const ESCAPEWORTHY_TAGS_CSS: &str =
|
208
|
+
pub const ESCAPEWORTHY_TAGS_CSS: &'static str =
|
209
209
|
"title, textarea, style, xmp, iframe, noembed, noframes, script, plaintext";
|
210
210
|
|
211
211
|
pub fn html_tags() -> Vec<HTMLTag> {
|
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
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen J. Torikian
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb_sys
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.2'
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- gjtorikian@gmail.com
|
58
58
|
executables: []
|
@@ -76,7 +76,6 @@ files:
|
|
76
76
|
- ext/selma/src/sanitizer.rs
|
77
77
|
- ext/selma/src/selector.rs
|
78
78
|
- ext/selma/src/tags.rs
|
79
|
-
- ext/selma/src/wrapped_struct.rs
|
80
79
|
- lib/selma.rb
|
81
80
|
- lib/selma/extension.rb
|
82
81
|
- lib/selma/html.rb
|
@@ -89,7 +88,7 @@ files:
|
|
89
88
|
- lib/selma/sanitizer/config/restricted.rb
|
90
89
|
- lib/selma/selector.rb
|
91
90
|
- lib/selma/version.rb
|
92
|
-
homepage:
|
91
|
+
homepage:
|
93
92
|
licenses:
|
94
93
|
- MIT
|
95
94
|
metadata:
|
@@ -97,7 +96,7 @@ metadata:
|
|
97
96
|
funding_uri: https://github.com/sponsors/gjtorikian/
|
98
97
|
source_code_uri: https://github.com/gjtorikian/selma
|
99
98
|
rubygems_mfa_required: 'true'
|
100
|
-
post_install_message:
|
99
|
+
post_install_message:
|
101
100
|
rdoc_options: []
|
102
101
|
require_paths:
|
103
102
|
- lib
|
@@ -112,8 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
111
|
- !ruby/object:Gem::Version
|
113
112
|
version: 3.3.22
|
114
113
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
116
|
-
signing_key:
|
114
|
+
rubygems_version: 3.5.3
|
115
|
+
signing_key:
|
117
116
|
specification_version: 4
|
118
117
|
summary: Selma selects and matches HTML nodes using CSS rules. Backed by Rust's lol_html
|
119
118
|
parser.
|
@@ -1,92 +0,0 @@
|
|
1
|
-
use magnus::{error::Error, exception, gc, value::Value, RTypedData, TryConvert, TypedData};
|
2
|
-
use std::{marker::PhantomData, ops::Deref};
|
3
|
-
|
4
|
-
// NOTE: My Rust isn't good enough to know what any of this does,
|
5
|
-
// but it was taken from https://cs.github.com/bytecodealliance/wasmtime-rb/blob/a843e4b4582a945f2c881b8bd3e2b87688ab5509/ext/src/helpers/wrapped_struct.rs#L4
|
6
|
-
|
7
|
-
/// A small wrapper for `RTypedData` that keeps track of the concrete struct
|
8
|
-
/// type, and the underlying [`Value`] for GC purposes.
|
9
|
-
#[derive(Debug)]
|
10
|
-
#[repr(transparent)]
|
11
|
-
pub struct WrappedStruct<T: TypedData> {
|
12
|
-
inner: RTypedData,
|
13
|
-
phantom: PhantomData<T>,
|
14
|
-
}
|
15
|
-
|
16
|
-
impl<T: TypedData> Clone for WrappedStruct<T> {
|
17
|
-
fn clone(&self) -> Self {
|
18
|
-
Self {
|
19
|
-
inner: self.inner,
|
20
|
-
phantom: PhantomData,
|
21
|
-
}
|
22
|
-
}
|
23
|
-
}
|
24
|
-
impl<T: TypedData> Copy for WrappedStruct<T> {}
|
25
|
-
|
26
|
-
impl<T: TypedData> WrappedStruct<T> {
|
27
|
-
/// Gets the underlying struct.
|
28
|
-
pub fn get(&self) -> Result<&T, Error> {
|
29
|
-
self.inner.try_convert()
|
30
|
-
}
|
31
|
-
|
32
|
-
/// Gets the underlying struct with a `'static` lifetime.
|
33
|
-
pub fn get_static(&self) -> Result<&'static T, Error> {
|
34
|
-
self.inner.try_convert()
|
35
|
-
}
|
36
|
-
|
37
|
-
/// Get the Ruby [`Value`] for this struct.
|
38
|
-
pub fn to_value(self) -> Value {
|
39
|
-
self.inner.into()
|
40
|
-
}
|
41
|
-
|
42
|
-
/// Marks the Ruby [`Value`] for GC.
|
43
|
-
pub fn mark(&self) {
|
44
|
-
gc::mark(&self.inner.into());
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
impl<T: TypedData> From<WrappedStruct<T>> for Value {
|
49
|
-
fn from(wrapped_struct: WrappedStruct<T>) -> Self {
|
50
|
-
wrapped_struct.to_value()
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
impl<T: TypedData> Deref for WrappedStruct<T> {
|
55
|
-
type Target = RTypedData;
|
56
|
-
|
57
|
-
fn deref(&self) -> &Self::Target {
|
58
|
-
&self.inner
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
impl<T: TypedData> From<T> for WrappedStruct<T> {
|
63
|
-
fn from(t: T) -> Self {
|
64
|
-
Self {
|
65
|
-
inner: RTypedData::wrap(t),
|
66
|
-
phantom: PhantomData,
|
67
|
-
}
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
impl<T> TryConvert for WrappedStruct<T>
|
72
|
-
where
|
73
|
-
T: TypedData,
|
74
|
-
{
|
75
|
-
fn try_convert(val: Value) -> Result<Self, Error> {
|
76
|
-
let inner = RTypedData::from_value(val).ok_or_else(|| {
|
77
|
-
Error::new(
|
78
|
-
exception::type_error(),
|
79
|
-
format!(
|
80
|
-
"no implicit conversion of {} into {}",
|
81
|
-
unsafe { val.classname() },
|
82
|
-
T::class()
|
83
|
-
),
|
84
|
-
)
|
85
|
-
})?;
|
86
|
-
|
87
|
-
Ok(Self {
|
88
|
-
inner,
|
89
|
-
phantom: PhantomData,
|
90
|
-
})
|
91
|
-
}
|
92
|
-
}
|