diff options
Diffstat (limited to 'libmproxy/utils.py')
-rw-r--r-- | libmproxy/utils.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libmproxy/utils.py b/libmproxy/utils.py index 4e53e6ce..4339ec6d 100644 --- a/libmproxy/utils.py +++ b/libmproxy/utils.py @@ -411,6 +411,18 @@ def parse_url(url): return scheme, host, port, path +def clean_hanging_newline(t): + """ + Many editors will silently add a newline to the final line of a + document (I'm looking at you, Vim). This function fixes this common + problem at the risk of removing a hanging newline in the rare cases + where the user actually intends it. + """ + if t[-1] == "\n": + return t[:-1] + return t + + def parse_size(s): """ Parses a size specification. Valid specifications are: |