jscheffl commented on code in PR #64154:
URL: https://github.com/apache/airflow/pull/64154#discussion_r2991104686


##########
providers/microsoft/winrm/src/airflow/providers/microsoft/winrm/operators/winrm.py:
##########
@@ -185,14 +184,37 @@ def evaluate_result(
 
             if enable_pickling:
                 return stdout_buffer
-            return 
b64encode(b"".join(stdout_buffer)).decode(self.output_encoding)
+            # Base64-encoded text is ASCII. Decode using ASCII to avoid
+            # producing non-ASCII characters when users set output_encoding
+            # to encodings like UTF-16.
+            return b64encode(b"".join(stdout_buffer)).decode("ascii")
 
         stderr_output = b"".join(stderr_buffer).decode(self.output_encoding)
         error_msg = f"Error running cmd: {self.command}, return code: 
{return_code}, error: {stderr_output}"
         raise AirflowException(error_msg)
 
     def _decode(self, output: str) -> bytes:
-        decoded_output = base64.standard_b64decode(output)
+        # The trigger emits base64 text which MUST be ASCII. Encode to ASCII
+        # bytes before decoding. Provide a clear error if the string contains
+        # non-ASCII characters so users can diagnose mismatched encodings.
+        try:
+            if isinstance(output, str):
+                output_bytes = output.encode("ascii")
+            else:
+                output_bytes = output
+        except UnicodeEncodeError as e:

Review Comment:
   We had similar problems in Docker and K8s provider, can you take a look 
here? https://github.com/apache/airflow/pull/62632/changes
   
   I suspect it is the same root cause, you get chars that are not JSON 
serializable in logs? In both Docker and K8s the fix was to replace incorrect 
surrogates, can happen if reads are in bytes and chunks are only "half" unicode 
chars (e.g. 2-byte char and you read only 1 byte at the end of a line.



-- 
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]

Reply via email to