unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Sebastian Spaeth <Sebastian@SSpaeth.de>
To: Patrick Totzke <patricktotzke@googlemail.com>, notmuch@notmuchmail.org
Subject: Re: [PATCH 2/2] [python] fix unsafe utf-8 decodings
Date: Wed, 17 Aug 2011 14:48:58 +0200	[thread overview]
Message-ID: <87wrecqk3p.fsf@SSpaeth.de> (raw)
In-Reply-To: <1313530667-10648-1-git-send-email-patricktotzke@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1313 bytes --]

On Tue, 16 Aug 2011 22:37:47 +0100, Patrick Totzke <patricktotzke@googlemail.com> wrote:
> This prevents unsafe calls to decode for return
> value None in get_authors/get_subject

Thanks for the heads up, I just pushed a modified version of this. Some
comments on the code below.

Sebastian

> -        tag = Tags._get(self._tags).decode('utf-8')
> +        tag = Tags._get(self._tags)
> +        if tag:
> +            tag = tag.decode('UTF-8')

This was already safe as 
  if not nmlib.notmuch_tags_valid(self._tags):
was making sure that something useful will be returned.

> -        return Thread._get_authors(self._thread).decode('UTF-8')
> +        authors = Thread._get_authors(self._thread)
> +        if authors:
> +            return authors.decode('UTF-8')
> +        return None

> -        return Thread._get_subject(self._thread).decode('UTF-8')
> +        subject = Thread._get_subject(self._thread)
> +        if subject:
> +            return subject.decode('UTF-8')
> +        return None

Modified this to say:

foo = get_foo()
if foo is None:
   return None
return foo.decode('UTF-8')

Otherwise you would fall into a trap when e.g. the subject is empty and
a '' is returned. Your code would have returned "None". My version will
return ''.

Thanks!

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

      reply	other threads:[~2011-08-17 12:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-22 14:11 [Patch] tag.py: Bugfix to avoid decode() on a NoneType object Michael Heinrich
2011-07-22 19:13 ` Patrick Totzke
2011-08-12  8:14 ` Sebastian Spaeth
2011-08-12 13:23   ` [PATCH] [python] decode headers from utf-8 to unicode Patrick Totzke
2011-08-15 13:49     ` Sebastian Spaeth
2011-08-16 21:37     ` [PATCH 2/2] [python] fix unsafe utf-8 decodings Patrick Totzke
2011-08-17 12:48       ` Sebastian Spaeth [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wrecqk3p.fsf@SSpaeth.de \
    --to=sebastian@sspaeth.de \
    --cc=notmuch@notmuchmail.org \
    --cc=patricktotzke@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).