andygrove commented on code in PR #372:
URL: https://github.com/apache/datafusion-spark/pull/372#discussion_r4643207866


##########
crates/spark/src/function/url/url_decode.rs:
##########
@@ -79,23 +79,21 @@ impl UrlDecode {
     ///
     /// * `Ok(Cow<str>)` - The decoded string, borrowed from `value` when there
     ///   was nothing to rewrite and owned otherwise
-    /// * `Err(DataFusionError)` - If the input is malformed or contains 
invalid UTF-8
+    /// * `Err(DataFusionError)` - If the input is malformed
     fn decode(value: &str) -> Result<Cow<'_, str>> {
         // Check if the string has valid percent encoding
         Self::validate_percent_encoding(value)?;
 
-        match Self::replace_plus(value.as_bytes()) {
+        // Bytes that are not valid UTF-8 become U+FFFD, like Java's 
`URLDecoder`
+        Ok(match Self::replace_plus(value.as_bytes()) {
             // No '+' was rewritten, so the decode can borrow from `value` 
itself.
-            Cow::Borrowed(bytes) => percent_decode(bytes)
-                .decode_utf8()
-                .map_err(|e| exec_datafusion_err!("Invalid UTF-8 sequence: 
{e}")),
+            Cow::Borrowed(bytes) => percent_decode(bytes).decode_utf8_lossy(),

Review Comment:
   Thanks for the update. I checked the fold against PySpark 4.2.0 with a few 
more shapes, like `%ED%A0%41`, `%ED%BF%BF`, `%ED%A0%80%80`, `%ED%9F%BF` and 
`%ED+%A0`, and they all match now. Looks good to me.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to