Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'patterns': 0.04; 'subject:text': 0.05; 'affected': 0.07; 'utf-8': 0.07; 'versions.': 0.07; 'badly': 0.09; 'bug.': 0.09; 'decodes': 0.09; 'exception.': 0.09; 'feature.': 0.09; 'terms,': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'bug,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'objects.': 0.16; 'said.': 0.16; 'wrote:': 0.18; 'bit': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'bytes': 0.24; 'cc:2**0': 0.24; 'supported': 0.26; 'header :In-Reply-To:1': 0.27; 'fixed': 0.29; 'chris': 0.29; 'am,': 0.29; 'said,': 0.30; 'message-id:@mail.gmail.com': 0.30; '>>>>': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'skip:b 30': 0.33; 'objects': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'should': 0.36; 'being': 0.38; 'mapping': 0.38; 'does': 0.39; 'how': 0.40; "you've": 0.63; 'provide': 0.64; 'mar': 0.68; 'invalid': 0.68; '2015': 0.84; 'to:none': 0.92; 'suffer': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=2Rus3Q3qFqseLccRw6tmlW8vcAeeAGdS34C9FvVZDLo=; b=09e+Q7fWIc/MlRwat6AuzX/cjH7GGzzocdsTkfh/llYPSzYu/IzmLsuIN9IQfGRdUL yU4dsBcGGSvUeXvRJEXXIlqA8gTqy2RD9vnF8BEsSygzY7jsQ0U+cWoX8pb3dXtDnzu+ wFj1qAW2nFDqf63VdmKV+qBz+c1d1OmQkYdyH3x8g4zo9DKgRRWpwdU4GoMm8WEdBHOW BUOgd4Rs+7SGubofPHXaXSX+QSwsppqNaWpgfT8UhuyUuMgelfgF5pUK8vW+chDa/prg ETtSAXmdzZ6TOf48kWvUOpZJ+A4E2BMh1HQ9i57B6H2FiYt9PWGk34NDCstV8DjLnKua 95LA== MIME-Version: 1.0 X-Received: by 10.50.111.136 with SMTP id ii8mr34473342igb.34.1425746488627; Sat, 07 Mar 2015 08:41:28 -0800 (PST) In-Reply-To: <87k2ysydtk.fsf@elektro.pacujo.net> References: <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <87k2ysydtk.fsf@elektro.pacujo.net> Date: Sun, 8 Mar 2015 03:41:28 +1100 Subject: Re: Newbie question about text encoding From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1425746496 news.xs4all.nl 2833 [2001:888:2000:d::a6]:60773 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87103 On Sun, Mar 8, 2015 at 3:25 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Mar 8, 2015 at 2:48 AM, Marko Rauhamaa wrote: >>> Steven D'Aprano : >>> >>>> Marko Rauhamaa wrote: >>>> >>>>> That said, UTF-8 does suffer badly from its not being >>>>> a bijective mapping. >>>> >>>> Can you explain? >>> >>> In Python terms, there are bytes objects b that don't satisfy: >>> >>> b.decode('utf-8').encode('utf-8') == b >> >> Please provide an example; that sounds like a bug. If there is any >> invalid UTF-8 stream which decodes without an error, it is actually a >> security bug, and should be fixed pronto in all affected and supported >> versions. > > Here's an example: > > b = b'\x80' > > Yes, it generates an exception. IOW, UTF-8 is not a bijective mapping > from str objects to bytes objects. That's not the same as what you said. All you've proven is that there are bit patterns which are not UTF-8 streams... which is a very deliberate feature. How does UTF-8 *suffer* from this? It benefits hugely! ChrisA