Skip to content

Commit 90f8e24

Browse files
authored
fix(s3): properly decode special chars in filename from change event (#768)
1 parent f595856 commit 90f8e24

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/ops/sources/amazon_s3.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@ use aws_config::BehaviorVersion;
44
use aws_sdk_s3::Client;
55
use globset::{Glob, GlobSet, GlobSetBuilder};
66
use std::sync::Arc;
7+
use urlencoding;
78

89
use crate::base::field_attrs;
910
use crate::ops::sdk::*;
1011

12+
/// Decode a form-encoded URL string, treating '+' as spaces
13+
fn decode_form_encoded_url(input: &str) -> Result<Arc<str>> {
14+
// Replace '+' with spaces (form encoding convention), then decode
15+
// This handles both cases correctly:
16+
// - Literal '+' would be encoded as '%2B' and remain unchanged after replacement
17+
// - Space would be encoded as '+' and become ' ' after replacement
18+
let with_spaces = input.replace("+", " ");
19+
Ok(urlencoding::decode(&with_spaces)?.into())
20+
}
21+
1122
#[derive(Debug, Deserialize)]
1223
pub struct Spec {
1324
bucket_name: String,
@@ -258,8 +269,9 @@ impl Executor {
258269
if record.event_name.starts_with("ObjectCreated:")
259270
|| record.event_name.starts_with("ObjectRemoved:")
260271
{
272+
let decoded_key = decode_form_encoded_url(&s3.object.key)?;
261273
changes.push(SourceChange {
262-
key: KeyValue::Str(s3.object.key.into()),
274+
key: KeyValue::Str(decoded_key),
263275
data: None,
264276
});
265277
}

0 commit comments

Comments
 (0)