From adbe2337f5ba849bf6ff4f61794887b9c1944157 Mon Sep 17 00:00:00 2001 From: Jussi Timperi <236182+Ban3@users.noreply.github.com> Date: Fri, 27 May 2022 18:11:53 +0300 Subject: [PATCH] fix(tone_convert): don't append tone number to empty input (#279) --- pypinyin/style/_tone_convert.py | 2 +- tests/contrib/test_tone_convert.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pypinyin/style/_tone_convert.py b/pypinyin/style/_tone_convert.py index cdbea82..244a302 100644 --- a/pypinyin/style/_tone_convert.py +++ b/pypinyin/style/_tone_convert.py @@ -545,7 +545,7 @@ def tone3_to_tone2(tone3, v_to_u=False): def _improve_tone3(tone3, neutral_tone_with_five=False): number = _get_number_from_pinyin(tone3) - if number is None and neutral_tone_with_five: + if number is None and neutral_tone_with_five and tone3 != '': tone3 = '{}5'.format(tone3) return tone3 diff --git a/tests/contrib/test_tone_convert.py b/tests/contrib/test_tone_convert.py index f3bac25..67dcf58 100644 --- a/tests/contrib/test_tone_convert.py +++ b/tests/contrib/test_tone_convert.py @@ -118,6 +118,8 @@ def test_tone_tone3(pinyin, result): @mark.parametrize('pinyin,neutral_tone_with_five,result', [ ['shang', False, 'shang'], ['shang', True, 'shang5'], + ['', False, ''], + ['', True, ''] ]) def test_tone_tone3_with_neutral_tone_with_five( pinyin, neutral_tone_with_five, result):