emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] url: Wrap cookie headers in url-http--encode-string.


From: Eli Zaretskii
Subject: Re: [PATCH] url: Wrap cookie headers in url-http--encode-string.
Date: Fri, 09 Sep 2016 18:04:19 +0300

> From: Alain Schneble <address@hidden>
> CC: Dmitry Gutov <address@hidden>, Eli Zaretskii <address@hidden>,
>       <address@hidden>, <address@hidden>
> Date: Fri, 9 Sep 2016 16:56:54 +0200
> 
> > (url-retrieve-synchronously "http://google.se";) ; sets a cookie
> > (let* ((url-request-data (encode-coding-string "æøå" 'utf-8)))
> >        (url-retrieve-synchronously "http://google.se";)) ; crashes
> 
> I was able to reproduce it but am a bit confused, since it doesn't
> signal an error when message-body "æøå" is replaced by "abc", while
> reusing the same cookie.
> 
> I tried to track it down with the following example. `cookie-val' is the
> value of the cookie-string:
> 
> (string-bytes cookie-val)
> => 131
> (string-bytes (encode-coding-string "æøå" 'utf-8))
> => 6
> (string-bytes (concat (encode-coding-string "æøå" 'utf-8) cookie-val))
> => 143 ' why?
> (string-bytes (concat (string-as-unibyte "abc") ans-cookie-val))
> => 134

Because a multibyte string with ASCII-only text has the same number of
bytes as it has characters.  While a multibyte string with non-ASCII
text has more bytes than characters, due to the way Emacs represents
characters internally (which is actually a superset of UTF-8).

> Why does concat behave that strangely?  What am I missing here?  Is the
> behavior of concatenating a unibyte and a multibyte string simply
> undefined?

No, it isn't undefined.  When some of the arguments are multibyte
strings, concat returns a multibyte string.  Nothing else would make
sense.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]