Skip to content

Commit

Permalink
Fix new S3 API and bytes with offset (awslabs#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
richarddavison authored Aug 1, 2024
1 parent acf79b7 commit c67e18d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ async function loadShims() {
loadShim(/collect-stream-body\.js/, "collect-stream-body.js"),
loadShim(/sdk-stream-mixin.browser\.js/, "sdk-stream-mixin.js"),
loadShim(/stream-collector\.js/, "stream-collector.js"),
loadShim(/splitStream.browser\.js/, "@smithy/split-stream.js"),
]);
}

Expand Down
13 changes: 10 additions & 3 deletions llrt_core/src/modules/llrt/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::{collections::HashMap, rc::Rc};

use quick_xml::{
escape::resolve_xml_entity,
events::{BytesStart, Event},
Reader,
};
Expand Down Expand Up @@ -99,10 +100,12 @@ impl<'js> XMLParser<'js> {
}
}

let entities = HashMap::new();

Ok(XMLParser {
tag_value_processor,
attribute_value_processor,
entities: HashMap::new(),
entities,
attribute_name_prefix: attribute_name_prefix.into(),
ignore_attributes,
text_node_name: text_node_name.into(),
Expand All @@ -116,7 +119,8 @@ impl<'js> XMLParser<'js> {
pub fn parse(&self, ctx: Ctx<'js>, xml: Value<'js>) -> Result<Object<'js>> {
let bytes = get_bytes(&ctx, xml)?;
let mut reader = Reader::from_reader(bytes.as_ref());
reader.config_mut().trim_text(true);
let config = reader.config_mut();
config.trim_text(true);

let mut current_obj = StackObject::new(ctx.clone())?;
current_obj.has_value = true;
Expand Down Expand Up @@ -186,7 +190,10 @@ impl<'js> XMLParser<'js> {
},
Ok(Event::Text(ref text)) => {
let tag_value = text
.unescape_with(|v| self.entities.get(v).map(|x| x.as_ref()))
.unescape_with(|v| {
resolve_xml_entity(v)
.or_else(|| self.entities.get(v).map(|x| x.as_ref()))
})
.or_throw(&ctx)?;
let tag_value = tag_value.as_ref();
let tag_value =
Expand Down
2 changes: 1 addition & 1 deletion llrt_utils/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn get_bytes_offset_length<'js>(
if let Some((array_buffer, source_length, source_offset)) = obj_to_array_buffer(obj)? {
let (start, end) = get_start_end_indexes(source_length, length, offset);
let bytes: &[u8] = array_buffer.as_ref();
return Ok(bytes[start + source_offset..end - source_offset].to_vec());
return Ok(bytes[(start + source_offset)..(end + source_offset)].to_vec());
}
}

Expand Down
5 changes: 5 additions & 0 deletions shims/@smithy/split-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export async function splitStream(stream) {
//stream is blob here
const typedArray = await stream.bytes();
return [typedArray.subarray(0, 3000), typedArray];
}

0 comments on commit c67e18d

Please sign in to comment.