From 1eca4e4578bce1ac10256ec4e6a983c313894889 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 24 Apr 2024 10:40:09 +0800 Subject: [PATCH] non_ascii_to_octal: Return the input string if it only contains printable ASCII characters --- pygmt/helpers/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pygmt/helpers/utils.py b/pygmt/helpers/utils.py index 1732dfb4e3f..7b06e6dc731 100644 --- a/pygmt/helpers/utils.py +++ b/pygmt/helpers/utils.py @@ -233,6 +233,10 @@ def non_ascii_to_octal(argstr): >>> non_ascii_to_octal("ABC ±120° DEF α ♥") 'ABC \\261120\\260 DEF @~\\141@~ @%34%\\252@%%' """ # noqa: RUF002 + # Return the string if it only contains printable ASCII characters from 32 to 126. + if all(32 <= ord(c) <= 126 for c in argstr): + return argstr + # Dictionary mapping non-ASCII characters to octal codes mapping = {}