Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## vNext (Month Day Year)

**New This Week**
- :bug: Bugfix: Fix parsing bug where whitespace was stripped when parsing XML (#590)

## v0.15 (June 29th 2021)
This week, we've added EKS, ECR and Cloudwatch. The JSON deserialization implementation has been replaced, please be
on the lookout for potential issues.
Expand Down
63 changes: 63 additions & 0 deletions aws/sdk/aws-models/s3-tests.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,69 @@ apply GetBucketLocation @httpResponseTests([
}
])

apply ListObjects @httpResponseTests([
{
id: "KeysWithWhitespace",
documentation: "This test validates that parsing respects whitespace",
code: 200,
bodyMediaType: "application/xml",
protocol: "aws.protocols#restXml",
body: """
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
<ListBucketResult
xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">
<Name>bucketname</Name>
<Prefix></Prefix>
<Marker></Marker>
<MaxKeys>1000</MaxKeys>
<IsTruncated>false</IsTruncated>
<Contents>
<Key> </Key>
<LastModified>2021-07-16T16:20:53.000Z</LastModified>
<ETag>&quot;etag123&quot;</ETag>
<Size>0</Size>
<Owner>
<ID>owner</ID>
</Owner>
<StorageClass>STANDARD</StorageClass>
</Contents>
<Contents>
<Key> a </Key>
<LastModified>2021-07-16T16:02:10.000Z</LastModified>
<ETag>&quot;etag123&quot;</ETag>
<Size>0</Size>
<Owner>
<ID>owner</ID>
</Owner>
<StorageClass>STANDARD</StorageClass>
</Contents>
</ListBucketResult>
""",
params: {
MaxKeys: 1000,
IsTruncated: false,
Marker: "",
Name: "bucketname",
Prefix: "",
Contents: [{
Key: " ",
LastModified: 1626452453,
ETag: "\"etag123\"",
Size: 0,
Owner: { ID: "owner" },
StorageClass: "STANDARD"
}, {
Key: " a ",
LastModified: 1626451330,
ETag: "\"etag123\"",
Size: 0,
Owner: { ID: "owner" },
StorageClass: "STANDARD"
}]
}
}
])

apply PutBucketLifecycleConfiguration @httpRequestTests([
{
id: "PutBucketLifecycleConfiguration",
Expand Down
4 changes: 2 additions & 2 deletions aws/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ fun discoverServices(allServices: Boolean, generateOnly: Set<String>): List<AwsS
val inTier1 = generateOnly.isEmpty() && tier1Services.contains(it.module)
allServices || inGenerateOnly || inTier1
}
if (generateOnly.isNotEmpty()) {
if (generateOnly.isEmpty()) {
val modules = services.map { it.module }.toSet()
tier1Services.forEach { service ->
check(modules.contains(service)) { "Service $service was in list of tier 1 services but not generated!" }
check(modules.contains(service)) { "Service $service was in list of tier 1 services but not generated! ($generateOnly)" }
}
}
return services
Expand Down
29 changes: 13 additions & 16 deletions aws/sdk/examples/s3/src/bin/list-objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use std::process;

use s3::{Client, Config, Region};

use aws_types::region::ProvideRegion;
use aws_types::region;

use aws_types::region::ProvideRegion;
use structopt::StructOpt;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::fmt::SubscriberBuilder;

#[derive(Debug, StructOpt)]
struct Opt {
Expand Down Expand Up @@ -44,31 +43,29 @@ async fn main() {
verbose,
} = Opt::from_args();

let region = default_region
.as_ref()
.map(|region| Region::new(region.clone()))
.or_else(|| aws_types::region::default_provider().region())
.unwrap_or_else(|| Region::new("us-west-2"));
let region = region::ChainProvider::first_try(default_region.map(Region::new))
.or_default_provider()
.or_else(Region::new("us-west-2"));

tracing_subscriber::fmt::init();

if verbose {
println!("S3 client version: {}", s3::PKG_VERSION);
println!("Region: {:?}", &region);

SubscriberBuilder::default()
.with_env_filter("info")
.with_span_events(FmtSpan::CLOSE)
.init();
println!(
"Region: {:?}",
region.region().expect("region must be set")
);
}

let config = Config::builder().region(&region).build();
let config = Config::builder().region(region).build();

let client = Client::from_conf(config);

match client.list_objects().bucket(&bucket).send().await {
Ok(resp) => {
println!("Objects:");
for object in resp.contents.unwrap_or_default() {
println!(" {}", object.key.expect("objects have keys"));
println!(" `{}`", object.key.expect("objects have keys"));
}
}
Err(e) => {
Expand Down
3 changes: 2 additions & 1 deletion rust-runtime/protocol-test-helpers/src/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ fn is_list(node: Node) -> bool {
fn non_empty_children<'a, 'input: 'a>(
node: Node<'a, 'input>,
) -> impl Iterator<Item = Node<'a, 'input>> {
let single_child = node.children().count() == 1;
node.children()
.filter(|c| !c.is_text() || !c.text().unwrap().trim().is_empty())
.filter(move |c| single_child || !c.is_text() || !c.text().unwrap().trim().is_empty())
}

#[cfg(test)]
Expand Down
23 changes: 20 additions & 3 deletions rust-runtime/smithy-xml/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,7 @@ pub fn try_data<'a, 'inp>(
loop {
match tokens.next().map(|opt| opt.map(|opt| opt.0)) {
None => return Ok(Cow::Borrowed("")),
Some(Ok(Token::Text { text })) if !text.as_str().trim().is_empty() => {
return unescape(text.as_str().trim())
}
Some(Ok(Token::Text { text })) => return unescape(text.as_str()),
Some(Ok(e @ Token::ElementStart { .. })) => {
return Err(XmlError::custom(format!(
"Looking for a data element, found: {:?}",
Expand Down Expand Up @@ -487,6 +485,25 @@ mod test {
assert_eq!(try_data(&mut scoped).unwrap(), "hello");
}

/// Whitespace within an element is preserved
#[test]
fn read_data_whitespace() {
let xml = r#"<Response> hello </Response>"#;
let mut doc = Document::new(xml);
let mut scoped = doc.root_element().unwrap();
assert_eq!(try_data(&mut scoped).unwrap(), " hello ");
}

#[test]
fn ignore_insignificant_whitespace() {
let xml = r#"<Response> <A> </A> </Response>"#;
let mut doc = Document::new(xml);
let mut resp = doc.root_element().unwrap();
let mut a = resp.next_tag().expect("should be a");
let data = try_data(&mut a).expect("valid");
assert_eq!(data, " ");
}

#[test]
fn read_attributes() {
let xml = r#"<Response xsi:type="CanonicalUser">hello</Response>"#;
Expand Down