From 50c94dcb9fa46fd24c1f4ea9e69e6c588b270f30 Mon Sep 17 00:00:00 2001 From: Daniel Zullo Date: Mon, 27 Jan 2020 21:33:25 +0100 Subject: [PATCH 1/2] Fix unicode in PR title or description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR title or description containing characters like áéíóúæç throws a UnicodeEncodeError. Python 2 default encoding is the ASCII encoding and raises a UnicodeEncodeError exception converting a Unicode string into the ASCII encoding if a code point (byte value) is greater than 127. The built-in open() is not consistent from Python 2 to 3. In Python 2 open() uses the ASCII encoding for opening a file in text mode to read/write contents while in Python 3 is platform-dependent encoding (whatever locale.getpreferredencoding() returns) or a specific encoding can be given as a parameter. Using io.open() instead of the built-in open() will handle correctly ASCII and Unicode strings when opening file to read/write contents and also ensures consistency from Python 2 to 3 (actually io.open() is the built-in open() in Python 3). Fix #276 --- git-hub | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git-hub b/git-hub index 343b1a3..9f28fec 100755 --- a/git-hub +++ b/git-hub @@ -50,6 +50,7 @@ import os.path import urlparse import argparse import subprocess +import io # Output levels according to user selected verbosity DEBUG = 3 @@ -322,13 +323,12 @@ def git_dir(): def editor(help_msg, msg=None): prog = git('var', 'GIT_EDITOR') fname = os.path.join(git_dir(), 'HUB_EDITMSG') - with open(fname, 'w') as f: - f.write(msg or '') - f.write(help_msg) + with io.open(fname, 'w') as f: + f.write(u''.join([msg or '', help_msg])) status = subprocess.call([prog + ' "$@"', prog, fname], shell=True) if status != 0: die("Editor returned {}, aborting...", status) - with open(fname) as f: + with io.open(fname) as f: msg = f.read() return msg From 781f4f2dd4c8275be1dc8d3c01ff3fbd62e1f550 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sat, 31 Oct 2020 23:01:51 +0100 Subject: [PATCH 2/2] Update release notes Old notes are removed and a note about the latest bugfix is added. --- relnotes/issue.feature.md | 1 - relnotes/pull-draft.feature.md | 3 --- relnotes/pull.feature.md | 1 - relnotes/unicode.bug.md | 4 ++++ 4 files changed, 4 insertions(+), 5 deletions(-) delete mode 100644 relnotes/issue.feature.md delete mode 100644 relnotes/pull-draft.feature.md delete mode 100644 relnotes/pull.feature.md create mode 100644 relnotes/unicode.bug.md diff --git a/relnotes/issue.feature.md b/relnotes/issue.feature.md deleted file mode 100644 index 56b6d61..0000000 --- a/relnotes/issue.feature.md +++ /dev/null @@ -1 +0,0 @@ -* Now `git-hub issue update -t TITLE` can be used to update issue's title. diff --git a/relnotes/pull-draft.feature.md b/relnotes/pull-draft.feature.md deleted file mode 100644 index 0ebe88e..0000000 --- a/relnotes/pull-draft.feature.md +++ /dev/null @@ -1,3 +0,0 @@ -### Create draft pull request - -* `git-hub pull new` accepts `--draft` or `-d` to create a draft pull request. diff --git a/relnotes/pull.feature.md b/relnotes/pull.feature.md deleted file mode 100644 index 17a9dd3..0000000 --- a/relnotes/pull.feature.md +++ /dev/null @@ -1 +0,0 @@ -* Now `git-hub pull new` accepts `--labels`, `--milestone` and `--assign` diff --git a/relnotes/unicode.bug.md b/relnotes/unicode.bug.md new file mode 100644 index 0000000..83c1771 --- /dev/null +++ b/relnotes/unicode.bug.md @@ -0,0 +1,4 @@ +### Fix unicode in PR title or description + +When using non-ASCII characters in PR title or description, an uncaught +exception was thrown. Not it is handled properly.