[ 
https://issues.apache.org/jira/browse/PROTON-2237?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17176567#comment-17176567
 ] 

ASF GitHub Bot commented on PROTON-2237:
----------------------------------------

kpvdr commented on a change in pull request #256:
URL: https://github.com/apache/qpid-proton/pull/256#discussion_r469505140



##########
File path: python/proton/_message.py
##########
@@ -90,13 +90,18 @@ def _check(self, err):
 
     def _check_property_keys(self):
         for k in self.properties.keys():
-            if isinstance(k, unicode):
-                # py2 unicode, py3 str (via hack definition)
+            # Check for string types. (py2: unicode, py3: str via type hack 
above)
+            # or string subclasses. Exclude string subclasses symbol and char.
+            if isinstance(k, unicode) and not (type(k) is symbol or type(k) is 
char):
+                # Convert string subclasses to string
+                if not type(k) is unicode:
+                    self.properties[unicode(k)] = self.properties.pop(k)
                 continue
-            # If key is binary then change to string
-            elif isinstance(k, str):
-                # py2 str
-                self.properties[k.encode('utf-8')] = self.properties.pop(k)
+            # If key is binary then change to string. Exclude bytes subclass 
decimal128.
+            # Mostly for py2 users who encode strings without using the u'' 
prefix
+            # but py3 bytes() type will be converted also

Review comment:
       I have thought of this, and it is a valid point. It was only for Py2 
users which did not use the u'' prefix that this conversion was included. For 
Py3 users, this could and probably should be an error.




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

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


> [python] Non-string message property keys not handled correctly
> ---------------------------------------------------------------
>
>                 Key: PROTON-2237
>                 URL: https://issues.apache.org/jira/browse/PROTON-2237
>             Project: Qpid Proton
>          Issue Type: Bug
>          Components: python-binding
>            Reporter: Kim van der Riet
>            Priority: Major
>
> The AMQP 1.0 spec allows only string keys for message properties.
> Proton's Python binding has a method (_message.py:91 _check_property_keys()) 
> for checking message property keys, but it does not handle all cases 
> correctly:
>  # Proton types Symbol and Char are derived from string, and are allowed in 
> the test. This results in an illegal encoding.
>  # Because in Python 2, many coders carelessly use string literals without 
> the required u'' prefix (and thus results in a bytes type), bytes types are 
> converted to unicode string types. However, the encode() function is being 
> used, which simply returns a binary type in Python 2 and raises an error in 
> Python 3. This should probably be the decode() method, which returns a string 
> and works for both Python 2 and 3.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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

Reply via email to