rusteerio 1.0.0 → 1.0.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.
package/Cargo.lock CHANGED
@@ -686,7 +686,7 @@ dependencies = [
686
686
 
687
687
  [[package]]
688
688
  name = "rusteerio"
689
- version = "1.0.0"
689
+ version = "1.0.1"
690
690
  dependencies = [
691
691
  "ego-tree",
692
692
  "html5ever",
package/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rusteerio"
3
- version = "1.0.0"
3
+ version = "1.0.1"
4
4
  edition = "2021"
5
5
  description = "Rust HTML5 parser and CSS selector engine for the rusteerio Node.js package"
6
6
  license = "MIT"
@@ -4,7 +4,7 @@ This file preserves third-party license and attribution notices for the Rust nat
4
4
 
5
5
  Generated by `node scripts/generate-notices.mjs` from `cargo metadata --locked`, crate license files, and the pinned supplemental sources recorded in `scripts/notices/sources.json`. It includes build dependencies and dependencies for all target platforms; a particular binary may use a subset. Identical notice texts are reproduced once and referenced below. The html5ever, markup5ever and html5gum crates contain local observer-hook and opt-in UTF-16 transport patches; their complete patched source and original notices are included in `native/vendor`. Other dependency source files are unmodified.
6
6
 
7
- Cargo.lock SHA-256: `972c2efc036e05a48803d6631cfd4f6026989898043bbd9aaf68bb52449c1716`.
7
+ Cargo.lock SHA-256: `42f353a71e79c84b5415fbfa8581ddd3c1aefa2b8c15f78a876631c8a9be2a68`.
8
8
 
9
9
  ## Source availability
10
10
 
@@ -18,6 +18,12 @@ The vendored compatibility suite and fixtures come from Cheerio 1.2.0, commit `e
18
18
 
19
19
  - [Cheerio MIT LICENSE](#notice-61c1e21d3a8ff20f) — [upstream source](https://github.com/cheeriojs/cheerio/blob/e3c7aaf9ed64fe3cb9a181e58a41c0fdd6dbfbfc/LICENSE)
20
20
 
21
+ ## htmlparser2 tokenizer port
22
+
23
+ The htmlparser2-compatible markup tokenizer in `native/src/markup_tokenizer.rs` ports the state machine of htmlparser2 10.1.0, commit `57ace50bf6eb3bfab0468deafe10d0a8a2f233aa`. Its original MIT notice is reproduced here.
24
+
25
+ - [htmlparser2 MIT LICENSE](#notice-204cfa747341660e) — [upstream source](https://github.com/fb55/htmlparser2/blob/57ace50bf6eb3bfab0468deafe10d0a8a2f233aa/LICENSE)
26
+
21
27
  ## Rust dependencies (112 locked packages)
22
28
 
23
29
  ### aho-corasick 1.1.5
@@ -2547,6 +2553,31 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
2547
2553
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2548
2554
  ```
2549
2555
 
2556
+ <a id="notice-204cfa747341660e"></a>
2557
+
2558
+ ### Notice 204cfa747341660e
2559
+
2560
+ ```text
2561
+ Copyright 2010, 2011, Chris Winberry <chris@winberry.net>. All rights reserved.
2562
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2563
+ of this software and associated documentation files (the "Software"), to
2564
+ deal in the Software without restriction, including without limitation the
2565
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
2566
+ sell copies of the Software, and to permit persons to whom the Software is
2567
+ furnished to do so, subject to the following conditions:
2568
+
2569
+ The above copyright notice and this permission notice shall be included in
2570
+ all copies or substantial portions of the Software.
2571
+
2572
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2573
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2574
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2575
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2576
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2577
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2578
+ IN THE SOFTWARE.
2579
+ ```
2580
+
2550
2581
  <a id="notice-209fbbe0ad52d923"></a>
2551
2582
 
2552
2583
  ### Notice 209fbbe0ad52d923
@@ -372,7 +372,12 @@ impl DomArena {
372
372
  node.extras.get("attribsPrefix"),
373
373
  )
374
374
  });
375
- for (name, value) in &node.attribs {
375
+ let attributes = super::js_property_order(
376
+ node.attribs
377
+ .iter()
378
+ .map(|(name, value)| (name.as_str(), value)),
379
+ );
380
+ for (name, value) in attributes {
376
381
  output.push(' ');
377
382
  match qualifiers {
378
383
  Some((namespaces, prefixes)) => super::push_attribute_name(
@@ -880,481 +885,30 @@ fn escape(value: &str, attribute: bool, xml: bool, utf8: bool, output: &mut Stri
880
885
  }
881
886
 
882
887
  pub(crate) fn parse_xml(source: &str, options: Value) -> DomArena {
883
- let mut arena = DomArena::from_records(vec![DomNode::new("root")], options);
884
- let mut parents = vec![0u32];
885
- parse_xml_segment(source, &mut arena, &mut parents, 0);
886
- arena
888
+ crate::tokenizer::parse_markup(source, options)
887
889
  }
888
890
 
889
- fn parse_xml_segment(source: &str, arena: &mut DomArena, parents: &mut Vec<u32>, base: usize) {
890
- let xml = arena.xml_mode();
891
- let indices = arena.options.get("withStartIndices") == Some(&Value::Bool(true))
892
- || arena.options.get("withEndIndices") == Some(&Value::Bool(true));
893
- let mut positions = if indices {
894
- vec![0usize; source.len() + 1]
895
- } else {
896
- Vec::new()
897
- };
898
- let mut utf16 = 0;
899
- let codec = arena.options.get("__utf16Codec") == Some(&Value::Bool(true));
900
- let mut escaped = false;
901
- if indices {
902
- for (at, ch) in source.char_indices() {
903
- for position in &mut positions[at..at + ch.len_utf8()] {
904
- *position = utf16;
905
- }
906
- if codec && ch == crate::codec::ESCAPE && !escaped {
907
- escaped = true;
908
- } else {
909
- utf16 += ch.len_utf16();
910
- escaped = false;
911
- }
912
- positions[at + ch.len_utf8()] = utf16;
913
- }
914
- }
915
- let source_position = |index: usize| {
916
- base + if indices {
917
- positions[index.min(source.len())]
918
- } else {
919
- index
920
- }
921
- };
922
- macro_rules! append_parsed {
923
- ($arena:expr,$parent:expr,$node:expr,$start:expr,$end:expr $(,)?) => {
924
- append_parsed(
925
- $arena,
926
- $parent,
927
- $node,
928
- source_position($start),
929
- source_position(($end).saturating_add(1)).saturating_sub(1),
930
- )
931
- };
932
- }
933
- let mut index = 0;
934
- let bytes = source.as_bytes();
935
- let decode = arena.options.get("decodeEntities") != Some(&Value::Bool(false));
936
- while index < bytes.len() {
937
- let start = index;
938
- if !xml {
939
- if let Some(name) = parents
940
- .last()
941
- .and_then(|id| arena.node(*id))
942
- .and_then(|node| node.name.as_deref())
943
- .filter(|name| matches!(*name, "script" | "style" | "xmp" | "textarea" | "title"))
944
- .map(str::to_owned)
945
- {
946
- let closing = format!("</{name}");
947
- let end = source.as_bytes()[index..]
948
- .windows(closing.len())
949
- .enumerate()
950
- .find(|(offset, candidate)| {
951
- candidate.eq_ignore_ascii_case(closing.as_bytes())
952
- && bytes
953
- .get(index + offset + closing.len())
954
- .is_none_or(|ch| *ch == b'>' || ch.is_ascii_whitespace())
955
- })
956
- .map_or(bytes.len(), |(offset, _)| index + offset);
957
- if end > index {
958
- let text = &source[index..end];
959
- let mut node = DomNode::new("text");
960
- node.data = Some(if decode && name == "title" {
961
- decode_entities_mode(
962
- text,
963
- false,
964
- false,
965
- arena.options.get("__utf16Codec") == Some(&Value::Bool(true)),
966
- )
967
- } else {
968
- text.into()
969
- });
970
- append_parsed!(
971
- arena,
972
- *parents.last().unwrap(),
973
- node,
974
- index,
975
- end.saturating_sub(1),
976
- );
977
- index = end;
978
- continue;
979
- }
980
- }
981
- if bytes[index] == b'<'
982
- && bytes.get(index + 1).is_some_and(|ch| {
983
- !ch.is_ascii_alphabetic() && !matches!(*ch, b'!' | b'?' | b'/')
984
- })
985
- {
986
- let mut node = DomNode::new("text");
987
- node.data = Some("<".into());
988
- append_parsed!(arena, *parents.last().unwrap(), node, index, index);
989
- index += 1;
990
- continue;
991
- }
992
- }
993
- if bytes[index] != b'<' {
994
- index = source[index..]
995
- .find('<')
996
- .map_or(bytes.len(), |offset| index + offset);
997
- let text = &source[start..index];
998
- let mut node = DomNode::new("text");
999
- node.data = Some(if decode {
1000
- decode_entities_mode(
1001
- text,
1002
- xml,
1003
- false,
1004
- arena.options.get("__utf16Codec") == Some(&Value::Bool(true)),
1005
- )
1006
- } else {
1007
- text.into()
1008
- });
1009
- append_parsed!(
1010
- arena,
1011
- *parents.last().unwrap(),
1012
- node,
1013
- start,
1014
- index.saturating_sub(1),
1015
- );
1016
- continue;
1017
- }
1018
- if source[index..].starts_with("<!--") {
1019
- let end = source[index + 4..]
1020
- .find("-->")
1021
- .map(|offset| index + 4 + offset);
1022
- let data_end = end.unwrap_or(bytes.len());
1023
- index = end.map_or(bytes.len(), |end| end + 3);
1024
- let mut node = DomNode::new("comment");
1025
- node.data = Some(source[start + 4..data_end].into());
1026
- append_parsed!(
1027
- arena,
1028
- *parents.last().unwrap(),
1029
- node,
1030
- start,
1031
- index.saturating_sub(1),
1032
- );
1033
- continue;
1034
- }
1035
- if source[index..].starts_with("<![CDATA[") {
1036
- let end = source[index + 9..]
1037
- .find("]]>")
1038
- .map(|offset| index + 9 + offset);
1039
- let data_end = end.unwrap_or(bytes.len());
1040
- index = end.map_or(bytes.len(), |end| end + 3);
1041
- if !xml && arena.options.get("recognizeCDATA") != Some(&Value::Bool(true)) {
1042
- let mut node = DomNode::new("comment");
1043
- node.data = Some(format!("[CDATA[{}]]", &source[start + 9..data_end]));
1044
- append_parsed!(
1045
- arena,
1046
- *parents.last().unwrap(),
1047
- node,
1048
- start,
1049
- index.saturating_sub(1)
1050
- );
1051
- continue;
1052
- }
1053
- let id = append_parsed!(
1054
- arena,
1055
- *parents.last().unwrap(),
1056
- DomNode::new("cdata"),
1057
- start,
1058
- index.saturating_sub(1),
1059
- );
1060
- let mut text = DomNode::new("text");
1061
- text.data = Some(source[start + 9..data_end].into());
1062
- append_parsed!(arena, id, text, start + 9, data_end.saturating_sub(1));
1063
- continue;
1064
- }
1065
- let mut cursor = index + 1;
1066
- let mut quote = None;
1067
- while cursor < bytes.len() {
1068
- let ch = bytes[cursor];
1069
- if let Some(q) = quote {
1070
- if ch == q {
1071
- quote = None;
1072
- }
1073
- } else if ch == b'\'' || ch == b'"' {
1074
- quote = Some(ch);
1075
- } else if ch == b'>' {
1076
- break;
1077
- }
1078
- cursor += 1;
1079
- }
1080
- if cursor >= bytes.len() {
1081
- let mut text = DomNode::new("text");
1082
- text.data = Some(source[index..].into());
1083
- append_parsed!(
1084
- arena,
1085
- *parents.last().unwrap(),
1086
- text,
1087
- start,
1088
- bytes.len().saturating_sub(1),
1089
- );
1090
- break;
1091
- }
1092
- index = cursor + 1;
1093
- let token = source[start + 1..cursor].trim();
1094
- if token.starts_with('!') || token.starts_with('?') {
1095
- let mut node = DomNode::new("directive");
1096
- node.name = Some(token.split_whitespace().next().unwrap_or("").into());
1097
- node.data = Some(token.into());
1098
- append_parsed!(arena, *parents.last().unwrap(), node, start, cursor);
1099
- continue;
1100
- }
1101
- if let Some(close) = token.strip_prefix('/') {
1102
- let close = close.split_whitespace().next().unwrap_or("");
1103
- if let Some(position) = parents.iter().rposition(|id| {
1104
- arena.nodes[*id as usize]
1105
- .name
1106
- .as_deref()
1107
- .is_some_and(|name| {
1108
- if xml {
1109
- name == close
1110
- } else {
1111
- name.eq_ignore_ascii_case(close)
1112
- }
1113
- })
1114
- }) {
1115
- for id in parents.drain(position..) {
1116
- if arena.options.get("withEndIndices") == Some(&Value::Bool(true)) {
1117
- arena.nodes[id as usize]
1118
- .extras
1119
- .insert("endIndex".into(), json!(source_position(cursor)));
1120
- }
1121
- }
1122
- }
1123
- continue;
1124
- }
1125
- let slash = token.ends_with('/');
1126
- let content = token.strip_suffix('/').unwrap_or(token);
1127
- let name_end = content.find(char::is_whitespace).unwrap_or(content.len());
1128
- let name = &content[..name_end];
1129
- if name.is_empty() {
1130
- continue;
1131
- }
1132
- let lower = arena
1133
- .options
1134
- .get("lowerCaseTags")
1135
- .and_then(Value::as_bool)
1136
- .unwrap_or(!xml);
1137
- let name = if lower {
1138
- name.to_ascii_lowercase()
1139
- } else {
1140
- name.into()
1141
- };
1142
- if !xml {
1143
- while parents
1144
- .last()
1145
- .and_then(|id| arena.node(*id))
1146
- .and_then(|node| node.name.as_deref())
1147
- .is_some_and(|open| implied_close(&name, open))
1148
- {
1149
- let id = parents.pop().unwrap();
1150
- if arena.options.get("withEndIndices") == Some(&Value::Bool(true)) {
1151
- arena.nodes[id as usize].extras.insert(
1152
- "endIndex".into(),
1153
- json!(source_position(start.saturating_sub(1))),
1154
- );
1155
- }
1156
- }
1157
- }
1158
- let foreign = matches!(name.as_str(), "svg" | "math")
1159
- || parents
1160
- .iter()
1161
- .rev()
1162
- .filter_map(|id| arena.node(*id))
1163
- .filter_map(|node| node.name.as_deref())
1164
- .find_map(|name| {
1165
- if matches!(
1166
- name,
1167
- "mi" | "mo"
1168
- | "mn"
1169
- | "ms"
1170
- | "mtext"
1171
- | "annotation-xml"
1172
- | "foreignobject"
1173
- | "desc"
1174
- | "title"
1175
- ) {
1176
- Some(false)
1177
- } else if matches!(name, "svg" | "math") {
1178
- Some(true)
1179
- } else {
1180
- None
1181
- }
1182
- })
1183
- .unwrap_or(false);
1184
- let self_close = slash
1185
- && (xml
1186
- || foreign
1187
- || arena.options.get("recognizeSelfClosing") == Some(&Value::Bool(true)));
1188
- let mut node = DomNode::new(if !xml && name == "script" {
1189
- "script"
1190
- } else if !xml && name == "style" {
1191
- "style"
1192
- } else {
1193
- "tag"
1194
- });
1195
- node.name = Some(name.clone());
1196
- node.attribs = parse_attributes(
1197
- &content[name_end..],
1198
- decode,
1199
- arena
1200
- .options
1201
- .get("lowerCaseAttributeNames")
1202
- .and_then(Value::as_bool)
1203
- .unwrap_or(!xml),
1204
- xml,
1205
- arena.options.get("__utf16Codec") == Some(&Value::Bool(true)),
1206
- );
1207
- let id = append_parsed!(arena, *parents.last().unwrap(), node, start, cursor);
1208
- let void = !xml && html_parser_void(&name);
1209
- if !self_close && !void {
1210
- parents.push(id);
1211
- } else if arena.options.get("withEndIndices") == Some(&Value::Bool(true)) {
1212
- arena.nodes[id as usize]
1213
- .extras
1214
- .insert("endIndex".into(), json!(source_position(cursor)));
1215
- }
1216
- }
1217
- }
1218
-
1219
- /// Incremental HTML-parser2/XML state; only incomplete markup/entity tokens are
1220
- /// buffered, while completed input is discarded after native tree construction.
891
+ /// Incremental htmlparser2/XML input. The complete input is tokenized once, so
892
+ /// tags and entities split across chunks parse exactly as one string does.
1221
893
  pub(crate) struct XmlStream {
1222
894
  pub arena: DomArena,
1223
- parents: Vec<u32>,
1224
895
  pending: String,
1225
- offset: usize,
1226
896
  }
1227
897
  impl XmlStream {
1228
898
  pub(crate) fn new(options: Value) -> Self {
1229
899
  Self {
1230
900
  arena: DomArena::from_records(vec![DomNode::new("root")], options),
1231
- parents: vec![0],
1232
901
  pending: String::new(),
1233
- offset: 0,
1234
902
  }
1235
903
  }
1236
904
  pub(crate) fn feed(&mut self, chunk: &str, finish: bool) {
1237
905
  self.pending.push_str(chunk);
1238
- let mut consumed = 0;
1239
- loop {
1240
- let input = &self.pending[consumed..];
1241
- let mut length = if finish {
1242
- input.len()
1243
- } else {
1244
- self.complete_prefix(input)
1245
- };
1246
- if !finish
1247
- && self.arena.options.get("__utf16Codec") == Some(&Value::Bool(true))
1248
- && input[..length]
1249
- .chars()
1250
- .rev()
1251
- .take_while(|ch| *ch == crate::codec::ESCAPE)
1252
- .count()
1253
- % 2
1254
- == 1
1255
- {
1256
- length -= crate::codec::ESCAPE.len_utf8();
1257
- }
1258
- if length == 0 {
1259
- break;
1260
- }
1261
- let segment = &input[..length];
1262
- parse_xml_segment(segment, &mut self.arena, &mut self.parents, self.offset);
1263
- self.offset += if self.arena.options.get("__utf16Codec") == Some(&Value::Bool(true)) {
1264
- crate::codec::logical_len(segment)
1265
- } else {
1266
- segment.encode_utf16().count()
1267
- };
1268
- consumed += length;
1269
- if consumed == self.pending.len() || finish {
1270
- break;
1271
- }
906
+ if finish {
907
+ let options = self.arena.options.clone();
908
+ self.arena = parse_xml(&std::mem::take(&mut self.pending), options);
1272
909
  }
1273
- self.pending.drain(..consumed);
1274
910
  }
1275
- fn complete_prefix(&self, input: &str) -> usize {
1276
- let bytes = input.as_bytes();
1277
- if input.is_empty() {
1278
- return 0;
1279
- }
1280
- if !self.arena.xml_mode() {
1281
- if let Some(name) = self
1282
- .parents
1283
- .last()
1284
- .and_then(|id| self.arena.node(*id))
1285
- .and_then(|node| node.name.as_deref())
1286
- .filter(|name| matches!(*name, "script" | "style" | "xmp" | "textarea" | "title"))
1287
- {
1288
- let close = format!("</{name}");
1289
- let closing = bytes
1290
- .windows(close.len())
1291
- .enumerate()
1292
- .find(|(at, value)| {
1293
- value.eq_ignore_ascii_case(close.as_bytes())
1294
- && bytes
1295
- .get(at + close.len())
1296
- .is_none_or(|ch| *ch == b'>' || ch.is_ascii_whitespace())
1297
- })
1298
- .map(|(at, _)| at);
1299
- match closing {
1300
- Some(0) if bytes.len() == close.len() => return 0,
1301
- Some(0) => {}
1302
- Some(index) => return safe_entity_prefix(input, index, name == "title"),
1303
- None => {
1304
- let mut end = input.len().saturating_sub(close.len() + 1);
1305
- while !input.is_char_boundary(end) {
1306
- end -= 1;
1307
- }
1308
- return safe_entity_prefix(input, end, name == "title");
1309
- }
1310
- }
1311
- }
1312
- }
1313
- if bytes[0] != b'<' {
1314
- let end = input.find('<').unwrap_or(input.len());
1315
- return safe_entity_prefix(
1316
- input,
1317
- end,
1318
- self.arena.options.get("decodeEntities") != Some(&Value::Bool(false)),
1319
- );
1320
- }
1321
- if input.starts_with("<!--") {
1322
- return input.find("-->").map_or(0, |index| index + 3);
1323
- }
1324
- if input.starts_with("<![CDATA[") {
1325
- return input.find("]]>").map_or(0, |index| index + 3);
1326
- }
1327
- let mut quote = None;
1328
- for (index, ch) in bytes.iter().copied().enumerate().skip(1) {
1329
- if let Some(q) = quote {
1330
- if ch == q {
1331
- quote = None;
1332
- }
1333
- } else if ch == b'\'' || ch == b'"' {
1334
- quote = Some(ch);
1335
- } else if ch == b'>' {
1336
- return index + 1;
1337
- }
1338
- }
1339
- 0
1340
- }
1341
- }
1342
- fn safe_entity_prefix(source: &str, end: usize, decode: bool) -> usize {
1343
- if decode {
1344
- if let Some(start) = source[..end].rfind('&') {
1345
- let tail = &source[start + 1..end];
1346
- if tail.len() < 64
1347
- && tail
1348
- .chars()
1349
- .all(|ch| ch.is_ascii_alphanumeric() || ch == '#')
1350
- {
1351
- return start;
1352
- }
1353
- }
1354
- }
1355
- end
1356
911
  }
1357
-
1358
912
  pub(crate) fn append_parsed(
1359
913
  arena: &mut DomArena,
1360
914
  parent: u32,
@@ -1424,70 +978,6 @@ pub(crate) fn implied_close(name: &str, open: &str) -> bool {
1424
978
  _ => false,
1425
979
  }
1426
980
  }
1427
- fn parse_attributes(
1428
- source: &str,
1429
- decode: bool,
1430
- lower: bool,
1431
- xml: bool,
1432
- codec: bool,
1433
- ) -> Map<String, Value> {
1434
- let bytes = source.as_bytes();
1435
- let mut index = 0;
1436
- let mut attrs = Map::new();
1437
- while index < bytes.len() {
1438
- while index < bytes.len() && bytes[index].is_ascii_whitespace() {
1439
- index += 1;
1440
- }
1441
- let start = index;
1442
- while index < bytes.len() && !bytes[index].is_ascii_whitespace() && bytes[index] != b'=' {
1443
- index += 1;
1444
- }
1445
- if start == index {
1446
- index += 1;
1447
- continue;
1448
- }
1449
- let name = &source[start..index];
1450
- while index < bytes.len() && bytes[index].is_ascii_whitespace() {
1451
- index += 1;
1452
- }
1453
- let mut value = "";
1454
- if bytes.get(index) == Some(&b'=') {
1455
- index += 1;
1456
- while index < bytes.len() && bytes[index].is_ascii_whitespace() {
1457
- index += 1;
1458
- }
1459
- if matches!(bytes.get(index), Some(b'\'' | b'"')) {
1460
- let quote = bytes[index];
1461
- index += 1;
1462
- let start = index;
1463
- while index < bytes.len() && bytes[index] != quote {
1464
- index += 1;
1465
- }
1466
- value = &source[start..index];
1467
- index += (index < bytes.len()) as usize;
1468
- } else {
1469
- let start = index;
1470
- while index < bytes.len() && !bytes[index].is_ascii_whitespace() {
1471
- index += 1;
1472
- }
1473
- value = &source[start..index];
1474
- }
1475
- }
1476
- let name = if lower {
1477
- name.to_ascii_lowercase()
1478
- } else {
1479
- name.into()
1480
- };
1481
- attrs.entry(name).or_insert_with(|| {
1482
- Value::String(if decode {
1483
- decode_entities_mode(value, xml, true, codec)
1484
- } else {
1485
- value.into()
1486
- })
1487
- });
1488
- }
1489
- attrs
1490
- }
1491
981
  pub(crate) fn decode_entities_mode(
1492
982
  source: &str,
1493
983
  xml: bool,