From bc673bc9433b7d9c7e669d45620dd9d36b5558d5 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 25 Apr 2024 08:21:38 +0800 Subject: [PATCH] non_ascii_to_octal: Return the input string if it only contains printable ASCII characters (#3199) --- pygmt/helpers/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pygmt/helpers/utils.py b/pygmt/helpers/utils.py index 66be427d937..781e0e4533f 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 = {}